Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of elements in a Form 2

Status
Not open for further replies.

juanferman

Programmer
Nov 14, 2001
40
0
0
US
Hi guys:

Any body of you knows how can I get the number of elements into a form ?

There is any way to also know what type of element is, checkbox, text, etc ?

Thanks in advance ===================
::) Juan F. Sarria
 
yep, you can calculate those:
document.your_form_name.elements.length
will tell you the total number of elements in your form.
using
document.your_form_name.elements[number].type will tell you the type

when you document loads, the browser automatically creates an array "elements" where all your form elements are stored. so in my second example, "number" should be the number in the browser's "elements" array that correlats to your element

HTH --------------------------------------------------
Goals are dreams with deadlines
 
document.myForm.elements.length

to know what the type of each element is do :

for (var ii = 0; ii < document.myForm.elements.length; ii++)
{
alert(document.myForm.elements[ii].type)
}

Hope this helps. Gary Haran
 
Thank you so much guys.

Both got a Star.

See you soon.
===================
::) Juan F. Sarria
 
xutopia,
I have no problems with that at all. happened to me several times as well. --------------------------------------------------
Goals are dreams with deadlines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top