Forms as Arrays

When you create a form in HTML, you create a form array. The development of an HTML form has a parallel array in JavaScript. As each form is developed, a form element is added to the array. Likewise, as each element within the form is developed, another subelement is added to the array. All forms in a form array are properties of the document object and are referenced as forms[n]. Within each forms[] element, all of the elements added in the <form> container are elements of the form[] object. Table 11.1 shows the HTML and JavaScript parallels in developing an array.

Table 11.1. Parallel HTML and JavaScript Forms and Form Elements
HTML JavaScript
<form name="first"> document.forms[0];
<input type=text> document.forms[0].elements[0]; ...

Get JavaScript Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.