views:

196

answers:

2

How can I iterate through all forms in a document using javascript?

+5  A: 

You can use

document.forms collection

See forms Collection

rahul
A: 

Hi

The code below will go through an html document, get all forms and do a pop-up alert of the names of each form.

var formsCollection = document.getElementsByTagName("form");
for(var i=0;i<formsCollection.length;i++)
{
   alert(formsCollection[i].name);
}

This is just a start to see if you are getting the reult you require. Thereafter, remove the alert and continue to do what you need to.

Yo Momma
Whats with the down vote?
Yo Momma
Obviously because your answer is less elegant then pulse .. I didn't give you vote down btw
c0mrade
I didn't vote, but note that the "name" attribute has little use on a form, so you'll seldom see it. One would find the uniqueness and addressability of "id" to be more useful, but neither affect the form's functionality.
Anonymous
Thanks for the input guys, much appreciated
Yo Momma