You can collect all the elements of a form into an Object, through which you can iterate to do whatever you want to.
The forms collection:

Code:
var oForm = document.forms[0]; 
  //holds the reference to the first form in the documents,  
 //you can access the other forms by changing 
 //the subscript
  
  var iLength = oForm.elements.length; //get the number of form elements
  
  //if you want to find the no. of text boxes in a form, here's how you do it.
  
  var oElements = oForm.elements; //get all the elements of the for to oElements
  var iTextCount = 0; //to store the no. of text boxes
  
  for(var i in oElements) //this is the JavaScript equivalent of Perl foreach
  {
     if(oElements[i].type == "text")
  	  iTextCount += 1;
  }
  
  //Now iTextCount stores the no. of text boxes in the form.
  //You can do a lot of things with forms in this way.

Hope this was helpful to you. Drop a query if you wanna know anything else.