HTML and CSS Reference
In-Depth Information
Validating Forms with JavaScript
Remember the example form that you created back in Lesson 11, “Designing Forms?”
It's shown again in Figure 15.1. It's a typical registration form for a website with several
required fields.
The registration
What happens when this form is submitted? In the real world, a script on the server side
validates the data that the visitor entered, stores it in a database or file, and then thanks
the visitor for her time.
But what happens if a visitor doesn't fill out the form correctly—for example, she
doesn't enter her name or choose a value for gender? The script can check all that
information and return an error. But because all this checking has to be done on the
server, and because the data and the error messages have to be transmitted back and
forth over the network, this process can be slow and takes up valuable resources.
JavaScript enables you to do error checking on the browser side before the form is ever
submitted to the server. This saves time for both you and your visitors because every-
thing is corrected on the visitors' side. After the data actually gets to your script, it's
more likely to be correct.
Search WWH ::

Custom Search