HTML and CSS Reference
In-Depth Information
Figure 11.8 An HTML form.
11.4 JavaScript and the form Object
In the previous example, the HTML form had nothing to do with JavaScript. After a form
has been filled out, the user clicks a Submit button and the information is normally sent
from the browser to a server in a URL-encoded format. The server then calls a server
helper application such as PHP or CGI to handle the information. So where does Java-
Script come into all of this? Well, before sending the form information to the server,
JavaScript can check to see if the form was filled out properly; for example, every input
field can be validated by JavaScript. It can check for empty fields or improperly filled out
fields. For example, it can check for the correct format of a credit card number, e-mail
address, zip code, and so on. In addition, rather than having the user submit the form,
submission can be controlled by JavaScript with its own submit() method. And by nam-
ing the forms, JavaScript can handle multiple forms and input types, respond to user-
initiated events, and call functions to handle the data that was submitted.
Search WWH ::

Custom Search