you can use the document.forms property to get an array of document forms, starting from index 0 for the first form element appeared in HTML code, and so on. or you may access a form having a "name" attribute, by using the name as the array index. so to access the first form in your HTML code use:
var f = document.forms[0];
and if the form has the name like "loginForm", you may reach it like:
var f = document.forms['loginForm'];
now that you have a reference to the form, you can access elements in it using the .elements property of the form. this property is an array that has the same indexing properties like the document.forms. so you can access each for element by its order in HTML code using numerical indexes, 0 for the first, or use named indexes by placing each element's name attribute as the index.
so to access the second element in the form you may use:
var el = f.elements[1];
or if the element has the name attribute of "username", you can reference it by:
var el = f.elements["username"];
this way you can reference to any element in any form in your document.