I have strange error when I decided to build ordinary web-form validation with classic javascript. There are several "onblur" handlers for input text fields and one "form-submit" handler.
When I use them like that:
function loginCheck() {
... return true of false
}
function passwordCheck() {
...
}
function formValidation() {
return loginCheck() && passwordCheck();
}
It doesn't work as I expect: "passwordCheck" never called if loginCheck is failed!
Finally I have workaround
function formValidation() {
ok = loginCheck();
ok &= passwordCheck();
return ok;
}
Now password check is executed. But when I choose:
function formValidation() {
ok = loginCheck();
ok = ok && passwordCheck();
return ok;
}
passwordCheck is never called again if loginCheck failed.
Moreover: loginCheck & passwordCheck return boolean values, but &= operator covert it to "0" or "1". "0" doesn't work for my onsubmit="return checkForm"
handler. I have to convert my &= result to boolean once again:
function formValidation() {
ok = loginCheck();
ok &= passwordCheck();
return ok != 0;
}
It is a normal behavior for javascript engines ?