Previous Example-|-Next Example-|-Return to Chapter Listing

Example 10.5:
Using Arrays to Refer to Forms


Type something into the text boxes. Then use the first button to see the form element names, and the second button to see the form element values.

Lastname:

FirstName:



This is the script we used in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- function DisplayElementNames() { for (i=0; i<4; i++) { alert("The element[" + i + "] name is " + document.Customer.elements[i].name) } } function DisplayElementContents() { for (i=0; i<4; i++) { alert("The element[" + i + "] value is \'" + document.Customer.elements[i].value + "\'") } } //--> </script> Later in the page we have this form: <FORM NAME="Customer"> <INPUT TYPE="button" NAME="But1" value="Display the elements names" onClick="DisplayElementNames()"> <INPUT TYPE="button" NAME="But2" value="Display the elements contents(Value)" onClick="DisplayElementContents()"><P> Lastname: <INPUT TYPE="text" NAME="Lastname"><P> FirstName: <INPUT TYPE="text" NAME="Firstname"> </FORM>
Previous Example-|-Next Example-|-Return to Chapter Listing