Jump to content

javascript AND or OR statements?


acctman

Recommended Posts

can someone explain why this is not working? I'm not getting any errors. i'm assuming its my AND and OR statements. I work it just like I would do in php. It works fine if i just have the regular If statement without the AND or OR

 

<script type="text/javascript">
function validate(form) {
  var city = document.getElementById('city').value;
  var ethnicity = document.getElementById('ethnicity').value;
  var zip = document.getElementById('zip').value;
  var country = document.getElementById('country').value; 
  var state_3 = document.getElementById('state_3').value;
  var state_2 = document.getElementById('state_2').value;  
  if(city == "") {
    inlineMsg('city','<strong>Error:</strong><br />Enter your city.',6);
    return false;
  }
  if(ethnicity == "") {
    inlineMsg('ethnicity','<strong>Error:</strong><br />Select your ethnicity.',6);
    return false;
  }

  if(country == "US" || "CA" && zip == "") {
    inlineMsg('zip','<strong>Error:</strong><br />Input your zipcode US/CAN.',6);
    return false;
  }  

  if(country == "") {
    inlineMsg('country','<strong>Error:</strong><br />Select your country.',6);
    return false;
  }

  if(country == "US" && state_3 == "") {
    inlineMsg('state_3','<strong>Error:</strong><br />Select your state.',6);
    return false;
  }  
  if(country == "CA" && state_2 == "") {
    inlineMsg('state_2','<strong>Error:</strong><br />Select your province.',6);
    return false;
  }

  return true;
}
</script>

Link to comment
Share on other sites

  if(country == "US" || "CA" && zip == "") {
    inlineMsg('zip','<strong>Error:</strong><br />Input your zipcode US/CAN.',6);
    return false;
  }  

That works if you convert that into PHP? o.O

 

Try this:

  if((country == "US" || country == "CA") && zip == "") {
    inlineMsg('zip','<strong>Error:</strong><br />Input your zipcode US/CAN.',6);
    return false;
  }  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.