I was looking at some sample code tutorials and noticed that on Javascript-coder.com, the author has several entries about form access which use two different methods of accessing form elements without explanation.
Example:
var myForm = document.forms["myForm"];
var elem = myForm[anInputName];
//OR
var myForm = document.forms["myForm"];
var elem = myForm.elements[anInputName];
Both appear to provide valid access to the element. Google just seems to crap out a bunch of syntax references. Why do both work?
Javascript forms have the elements collection which is an array of all form elements, but JS will also allow you to access the form elements by object key, as in your first example above.