I have a strange error when I decided to create a simple web form validation using classic javascript. There are several onblur handlers for text input fields and one "form-submit" handler.
When I use them like this:
function loginCheck() { ... return true of false } function passwordCheck() { ... } function formValidation() { return loginCheck() && passwordCheck(); }
It does not work as I expect: "passwordCheck" was never called if loginCheck failed!
Finally, I have a workaround
function formValidation() { ok = loginCheck(); ok &= passwordCheck(); return ok; }
Now the password is checked. But when I choose:
function formValidation() { ok = loginCheck(); ok = ok && passwordCheck(); return ok; }
passwordCheck is never called again if loginCheck failed.
In addition: loginCheck and passwordCheck return boolean values, but the & = operator hides it to "0" or "1". "0" does not work for my onsubmit="return checkForm" handler. I need to convert my & = result to boolean again:
function formValidation() { ok = loginCheck(); ok &= passwordCheck(); return ok != 0; }
Is this normal behavior for javascript engines?
javascript
Andrew Florko Oct 22 '11 at 10:12 2011-10-22 10:12
source share