Event handlers review

Event handlers

Event handlers execute user-defined code in response to certain events, such as button clicks, text changes and form loadings. JavaScript's event handlers are:

The Form object

Form elements, such as selection lists and text boxes, must be contained within an HTML form. The syntax for creating a form is:

<form name="formName" action="(form action") method="(get/post)">
...
</form>

Accessing form information

The Document object contains a forms array, with each element referencing subsequent forms on the page. Each form on a page contains an elements array, with each element referencing subsequent form element objects. Alternatively, the name attribute from an object's definition can be used in place of array refrences.

The syntax to refer to properties of form objects is '(form reference).(element reference).(property)'. The two methods of accessing form elements are illustrated by the following code:

forms[0].elements[0].value

or

formName.elementName.value

Browser incompatibilities

With careful coding, incompatibility issues raised by Internet Explorer can be kept to a minimum. However, you may find that you need to write browser-specific code, and in those instances, you can use the Navigator object to determine which browser is being used to view the page. The two most important properties of the Navigator object are appName and appVersion.