• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

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];
<input type=button> document.forms[0].elements[1];
<textarea></textarea> document.forms[0].elements[2];
</form> 
<form name="second"> document.forms[1];
<input type=text> document.forms[1].elements[0];
<input type=button> document.forms[1].elements[1];
<textarea></textarea> document.forms[1].elements[2];
</form>



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint