-1

i wanted to validate my form but im stuck with the validation of formfield persnr. It won´t compare the string. For this i already tried the comparison and operators (or || ). The validation of the other fields is ok. Did i use the operators wrong?

function checkForm() {
    var strFehler = '';
    if (document.forms[0].user.value == "user")
        strFehler += "user not ok!\n";
    if (document.forms[0].test.value == "")
        strFehler += "test not ok!\n";
    if (document.forms[0].time.value == "")
        strFehler += "time not ok";
    if (document.forms[0].cost.value == "")
        strFehler += "cost not ok!\n";
    if (document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286")
    strFehler += "persnr false!\n";
    if (strFehler.length > 0) {
        alert("problems!!: \n\n" + strFehler);
        return (false);
    }
}

I expected that the validation would show an alert if the value isn´t 13088 or 10286 but no message pops up.

Pointy
  • 405,095
  • 59
  • 585
  • 614
D2a
  • 5
  • 3

1 Answers1

1

This:

if (document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286")

Needs to be changed to this:

if ((document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286"))

Your are missing parentheses to have both conditions inside the the if statement.

Word Rearranger
  • 1,306
  • 1
  • 16
  • 25