3 fields check...

Results 1 to 2 of 2

Thread: 3 fields check...

  1. #1
    Join Date
    Dec 1969

    Default 3 fields check...

    I have 3 fields:<BR>State,city and zip code.<BR><BR>The user can enter data to either the state and city OR to the zip code.<BR><BR>I got this check but it&#039;s not working how I want it to:<BR>if ( document.reg.state.value == "" && document.reg.city.value == "" && document.reg.zipCode.value == "")<BR> {<BR> alert(&#039;Please select State and City OR Zip Code&#039;);<BR> return false;<BR> }<BR><BR>As for the alert "Both State and City has to be completed ", this alert should pop only when there is no zip code, AND the user forgot to enter either State or City.<BR><BR>What do I need to add to this?

  2. #2
    Join Date
    Dec 1969

    Default Since you can express the conditions...

    ...in English, why not try just translating the English to code????<BR><BR>The user can enter data to either the state and city OR to the zip code<BR><BR>Okay, so in PSEUDO-code:<BR><BR> IF state-is-given AND city-is-given THEN<BR> all is okay<BR> ELSE IF zip-is-given THEN<BR> all is okay<BR> ELSE<BR> zap the idiot user<BR><BR>Now all you have to do is translate the pseudo-code to JavaScript.<BR><BR>Are you up to that?<BR><BR>[Yes, there are other ways to solve this, but why not try the straightforward way first?]<BR><BR>I&#039;ll get you started:<BR><BR>&#060;SCRIPT&#062;<BR>function checkForStateCityZip( )<BR>{<BR> var form = doucment.reg;<BR> if ( ... )<BR> {<BR> return true;<BR> }<BR> if ( ... )<BR> {<BR> return true;<BR> }<BR> alert(...);<BR> return false;<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>See? Nice and straightforward.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts