Validating the HTML form

Seven part section: 1 2 3 4 5 6 7

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.

And that's it for Javascript forms. We can move on. The next section is all about manipulating HTML elements with Javascript.