From: jr on
There are 4 + fields in a search form, bu, cart_id, zoneid, zonenm.
bu is required, search_bu in the form
however if the zoneid is searched on it requires the zonenm to make a
complete search.

testing:
1. click on BU & zoneid
asks for zonenm

2. click on cart_id
asks for bu this is okay but then
it asks for the zonenm ???????

The only time I want it to ask for the zonenm is when the zoneid is
checked.
I have the zonenm in a nested if that first asks whether there is a
value in the zoneid.
It shouldn't hit this 2nd if??

3. if I click zoneid
asks for the bu okay
put in bu
asks for zonenm okay

4. put in zone num
asks for bu
put in bu
it submits but without asking for the zoneid ????

thanks,
Janis r.





<script type="text/javascript">
function checkscript() {

if (document.forms[0].search_bu.value == '' ||
document.forms[0].search_bu.value == null) {
// something else is wrong
alert('The Business Unit is a required field!');
return false;
}
else if (document.forms[0].search_zoneid.value != '' ||
document.forms[0].search_zoneid.value != null ) {

if (document.forms[0].search_zonenm.value == '' ||
document.forms[0].search_zonenm.value == null ){
alert('You must input the zone number if you search on
zone ID');
return false;
}

}
else if (document.forms[0].search_zonenm.value != '' ||
document.forms[0].search_zonenm.value != null ) {

if (document.forms[0].search_zoneid.value == '' ||
document.forms[0].search_zoneid.value == null ){
alert('You must input the zone number if you search on
zone ID');
return false;
}

}
// if true you can submit the form

return true;
}
</script>
From: Richard Cornford on
jr wrote:
<snip>
> else if (document.forms[0].search_zoneid.value != '' ||
> document.forms[0].search_zoneid.value != null ) {
<snip>

This logical OR expression is certainly wrong. The possible values of
the - value - property of form controls are strings or null. If the -
value - of the field is null then that value is not equal to an empty
string and so the left hand side of the OR is true (making the whole
expression's result true), and if the - value - is the empty string then
the value is not equal to null, so the right hand side of the OR true
(making the whole expression's result true). All other possible values
are non-empty strings, which will not be equal to both null and the
empty string. The - if - is always true and its body will be executed
unconditionally.

A logical AND operation seems a better candidate; that the - value - not
be equal to the empty string AND it not be equal to null. That way you
only enter the - if - body when the value is a non-empty string value.

Richard.