November 16, 1999 - Referencing Forms | WebReference

November 16, 1999 - Referencing Forms

Yehuda Shiran November 16, 1999
Referencing Forms
Tips: November 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Each <FORM>...</FORM> tag pair defines one form. A single HTML document can contain several different forms, containing various form elements. JavaScript provides two main ways to reference a form:


Take a look at the following document:

<FORM NAME="firstForm"></FORM>
<FORM NAME="thirdForm">
<INPUT TYPE="text" NAME="myField" SIZE="30">

The value of the text field in the third form can be retrieved in one of the following fashions:


Notice that the forms array (a property of the document object) is zero-based. In other words, 0 reflects the first form, 1 reflects the second form, and so forth.

Note that the document.forms object can also be used with the name of the desired form (like a Visual Basic collection):


The forms array is supported by all JavaScript-enabled browsers, including Navigator 2.0x and Internet Explorer 3.0x.