validate 3 fields

J

jr

Something is not working on the validation script. The bu is
required in a search form. Zonenm and zoneid are required together.
If someone searches on a bu and also a zoneid, then they must also
search on the zonenm and vice versa.So it is either all 3 or just the
bu. The bu validation always works. HOwever if I search on bu and
zoneid for example, I get a message asking for zonenm, but
alternatively, if I ask for the zoneid and bu, it should ask for the
zonenm. I tried it with the 3rd else if as an else instead of else if
but then I got a syntax error. thanks,
<script type="text/javascript">
function checkscript() {
var ele = document.forms[0].elements;
if (!ele.search_bu.value) {
alert('The Business Unit is a required field!');
return false;
} else if (ele.search_zoneid.value && !ele.search_zonenm.value) {
alert('Zone ID but no zone number');
return false;

} else if(ele.search_zonenm.value && !ele.search_zoneid.value) {
alert('Zone Number but no zone id');
return false;
}
return true;
}
</script>
 
D

David Mark

Something is not working on the  validation script.  The bu is
required in a search form.  Zonenm and zoneid are required together.
If someone searches on a bu and also a zoneid, then they must also
search on the zonenm and vice versa.So it is either all 3 or just the
bu.  The bu validation always works.  HOwever if I search on bu and
zoneid for example, I get a message asking for zonenm, but
alternatively, if I ask for the zoneid and bu, it should ask for the
zonenm.  I tried it with the 3rd else if as an else instead of else if
but then I got a syntax error.  thanks,
<script type="text/javascript">
 function checkscript() {
    var ele = document.forms[0].elements;
    if (!ele.search_bu.value) {
        alert('The Business Unit is a required field!');
        return false;
    } else if (ele.search_zoneid.value && !ele.search_zonenm.value) {
        alert('Zone ID but no zone number');
        return false;

    } else if(ele.search_zonenm.value && !ele.search_zoneid.value) {
        alert('Zone Number but no zone id');
        return false;
    }
    return true;
 }
 </script>

Why use else's at all? Each conditional branch returns after all. ;)
 
S

SAM

Le 7/29/10 6:50 AM, jr a écrit :
Something is not working on the validation script. The bu is
required in a search form. Zonenm and zoneid are required together.

aren't you too tired to always ask the same thing ?

can't you think by yourself ?

if ( bu.value ) {
if ( zoneid.value && !zonenum.value ) { blah 1 }
else
if ( !zoneid.value && zonenum.value ) { blah 2 }
}
else { blah 0 }

the "blah"s must return false
 
D

Denis McMahon

Something is not working on the validation script. ...
but then I got a syntax error. thanks,

What was the error message, and what line in the script did it identify?

Rgds

Denis McMahon
 
J

jr

What was the error message, and what line in the script did it identify?

Rgds

Denis McMahon

There wasn't an error message but the user could perform the search
incorrectly. It is an enforced business rule to search only on both.
 
J

jr

What was the error message, and what line in the script did it identify?

Rgds

Denis McMahon

I believe I this one does work. I was testing on the wrong page or
something else. It is not elegant but it works.
 
J

jr

Le 7/29/10 6:50 AM, jr a écrit :


aren't you too tired to always ask the same thing ?

can't you think by yourself ?

if ( bu.value ) {
   if ( zoneid.value && !zonenum.value ) { blah 1 }
   else
   if ( !zoneid.value && zonenum.value ) { blah 2 }
   }
else { blah 0 }

the "blah"s must return false
I'm sorry I figured it out. Yours is better but the other one works.
I need to read a Javascript book. I have done hardly any javascript
and the format is slightly different than php.
 
S

SAM

Le 7/29/10 9:21 PM, jr a écrit :
I'm sorry I figured it out. Yours is better but the other one works.
I need to read a Javascript book. I have done hardly any javascript
and the format is slightly different than php.

not so much ... not so much ... if / else are the same everywhere ;-)
 
D

David Mark

Le 7/29/10 9:21 PM, jr a écrit :







not so much ... not so much ... if / else  are the same everywhere ;-)

Pretty much and you don't need an else if the previous conditional
clause exits the function. JSLint is good for spotting these issues.
 
S

SAM

Le 7/30/10 12:39 AM, David Mark a écrit :
Pretty much and you don't need an else if the previous conditional
clause exits the function.

Absolutely !
(posted too quickly :-( )
 
C

Captain Paralytic

Something is not working on the  validation script.  The bu is
required in a search form.  Zonenm and zoneid are required together.
If someone searches on a bu and also a zoneid, then they must also
search on the zonenm and vice versa.So it is either all 3 or just the
bu.  The bu validation always works.  HOwever if I search on bu and
zoneid for example, I get a message asking for zonenm, but
alternatively, if I ask for the zoneid and bu, it should ask for the
zonenm.  I tried it with the 3rd else if as an else instead of else if
but then I got a syntax error.  thanks,
<script type="text/javascript">
 function checkscript() {
    var ele = document.forms[0].elements;
    if (!ele.search_bu.value) {
        alert('The Business Unit is a required field!');
        return false;
    } else if (ele.search_zoneid.value && !ele.search_zonenm.value){
        alert('Zone ID but no zone number');
        return false;
    } else if(ele.search_zonenm.value && !ele.search_zoneid.value) {
        alert('Zone Number but no zone id');
        return false;
    }
    return true;
 }
 </script>

Why use else's at all?  Each conditional branch returns after all.  ;)

You are assuming that the poster is an intelligent being. It is
however JRough, to whom intelligence is a foreign land.
 
D

David Mark

Something is not working on the  validation script.  The bu is
required in a search form.  Zonenm and zoneid are required together..
If someone searches on a bu and also a zoneid, then they must also
search on the zonenm and vice versa.So it is either all 3 or just the
bu.  The bu validation always works.  HOwever if I search on bu and
zoneid for example, I get a message asking for zonenm, but
alternatively, if I ask for the zoneid and bu, it should ask for the
zonenm.  I tried it with the 3rd else if as an else instead of elseif
but then I got a syntax error.  thanks,
<script type="text/javascript">
 function checkscript() {
    var ele = document.forms[0].elements;
    if (!ele.search_bu.value) {
        alert('The Business Unit is a required field!');
        return false;
    } else if (ele.search_zoneid.value && !ele.search_zonenm.value) {
        alert('Zone ID but no zone number');
        return false;
    } else if(ele.search_zonenm.value && !ele.search_zoneid.value) {
        alert('Zone Number but no zone id');
        return false;
    }
    return true;
 }
 </script>
Why use else's at all?  Each conditional branch returns after all.  ;)

You are assuming that the poster is an intelligent being. It is
however JRough, to whom intelligence is a foreign land.

You are assuming I know one "JR" (or "jr") from the next. That's why
people should use unique "handles" on Usenet, preferably their real
name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top