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
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;
    }
}

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.