Jump to content

[SOLVED] Simple OR operator question.


Ty44ler

Recommended Posts

I'm trying to not allow my users to enter in n/a in my form ex... "N/A" "n/A" "na"

 

My code trips the alert every time no matter what is entered in the cell... Why is it doing that?

 

function appliance() {
if (document.ComplianceForm.Appliance.value=="n/a" || "N/A" || "n/A" || "N/a") {
alert("You cannot enter any variation of n/a in this cell.")
}
else {
return false;
}; 
}

Link to comment
https://forums.phpfreaks.com/topic/182178-solved-simple-or-operator-question/
Share on other sites

you have to compare the field with each value like the following the reason its not working because a string returns true if ("N/A") will return true

 

function appliance() {
    var appliance_value = document.ComplianceForm.Appliance.value;
    if (appliance_value=="n/a" || appliance_value == "N/A" || appliance_value == "n/A" || appliance_value == "N/a") {
      alert("You cannot enter any variation of n/a in this cell.")
    }
    else {
      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.