This tutorial will show you how to create a Java Script-enabled form that checks whether a user has filled in the form correctly before it's sent to the server. First we'll explain why form validation is a useful thing, and then build up a simple example form, explaining things as we go along.
At the end, there's a little exercise to keep you busy too!
Validating when the user submits the form mens guide to finding and dating a sugar momma
Again, you might like to open the source code for this form in a separate window, so that you can refer to it as we talk you through.
Like our previous example, this page has a form called start at zero (for the first option).
Our example is very simple as it only checks one field.
Let's expand this example with a more complex function that checks lots of form fields.
Form validation is the process of checking that a form has been filled in correctly before it is processed.
For example, if your form has a box for the user to type their email address, you might want your form handler to check that they've filled in their address before you deal with the rest of the form.
The way to get around this is to be sure that all forms on the same web page have unique names for each field.
In the case of the name field it could be indicated individually by , etc...
The form will include one text field called "Your Name", and a button.
Our validation script will ensure that the user enters their name before the form is sent to the server. Try pressing the Send Details button without filling anything in the "Your Name" field.
In this simple form, no actual data will be submitted; we're only testing it for validation purposes. In this tutorial and example we are only interested in the validation routines, and not where the actual form data will be submitted.