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
https://forums.phpfreaks.com/topic/156302-javascript-and-or-or-statements/
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;
  }  

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.