JAVASCRIPTINGTaking advantage of the elements array

JAVASCRIPTING
Taking advantage of the elements array

Steven W. Disbrow

Listing 1. Accessing poorly-named HTML controls from JavaScript.


<HTML>
<HEAD>
<TITLE>Using the "elements" Array</TITLE>
<script language="javascript">
function doVote( theForm) {
	var pFirst = theForm.elements["first name"].value;
	var pLast = theForm.elements["last name"].value;
	alert( "You voted for " + pFirst + " " + pLast);
	}
</script>
</HEAD>
<BODY>
<form name="form1">
Enter the name of your favorite American President:<br>
First: <input type="text" name="first name" value="George">
<br>
Last: <input type="text" name="last name" value="Washington">
<br>
<input type="button" value="Vote"
 onClick="doVote( this.form)">
</form>
</BODY>
</HTML>

About the Author

Steven Disbrow is the owner of EGO Systems, a computer consulting firm in Chattanooga, TN. He can be contacted at [email protected].