11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Just as the Document contains a collection of tags, each form contains a collection<br />

of form fields that can be accessed through the elements[] collection. So, given the form of the<br />

previous example, window.document.customerform.elements[0] refers to the first field.<br />

Similarly, we could access the fields by name, for example, with window.document<br />

.customerform.firstname or window.document.customerform.elements["firstname"].<br />

We could also iterate through the collection of form fields after examining the elements[]<br />

collection‘s length property (window.document. customerform.elements .length).<br />

Conveniently, the length of the elements[] collection is also stored in the Form. This gives us<br />

a shorthand notation for looking at the number of fields: document .customerform.length.<br />

Before taking a look at the objects that represent the different kinds of form fields, we present a<br />

brief example to demonstrate the access of the various Form object properties and methods.<br />

<br />

<br />

<br />

Form Object Test<br />

<br />

<br />

<br />

Test Form<br />

<br />

Name:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!