Get latest news and Web Designing tutoria

Thursday, 4 June 2015

Validating the HTML form

The only thing left to do is to return to the validate function. After all the other four functions have been executed, the four variables will either be true or false. We only want to send the form if all four variables are true. If they are not then the user has made an error and we need to keep them on the same page. Here's the rest of the code for the validate function:

Javascript code to validate a HTML form


The new part is the IF … ELSE statement. It's uses the AND operator (&&) three times. IF all four variables are true we have this line:
document.frmOne.submit();
You only need the word submit with a pair of round brackets on the end. This is enough to send the form to whatever you have for the ACTION attribute for the FORM tag.
If you don't want to send the form the only thing you need to do is to set the return value to false.

0 comments:

Post a Comment