Building Forms with JavaScript

From Techotopia
Revision as of 15:30, 15 May 2007 by Neil (Talk | contribs)

Jump to: navigation, search

The ability to interact with, and obtain information from web site visitors, is a central theme behind the JavaScript language. No JavaScript book would be complete, therefore, without exploring how to handle Graphical User Interface Componments (GUI) objects such as buttons, text input fields, checkboxes, radio boxes and selections, together with the Form object which brings them all together.

The JavaScript Form Object

The JavaScript Form object serves a number purposes. It acts a container for all of the GUI objects that make up a form. It also acts as the mechansism for grouping together the information provided by the user and sending it back to the server for processing.

The <form> takes a number of attributes of which the following are the most commonly used:

  • name - the name of the form, which will be used when referencing objects within the the form four JavaScript code.
  • method - the method by which data is sent to the server. This will either be "GET" ot "POST" depdniong on the server-side configuration.
  • action - the URL of the CGI script to which the data entered by the user will be sent. It is also possible to use mailto: to have the data sent to an email address.

The following is an example of a form called registerForm which