PDA

View Full Version : getElementByID question



alex57
Jan 29th, 2007, 02:12 PM
I know you can use this syntax to reference an element:


getElementbyid.forms[5].element[4].value

What happens if you want to reference an element by you dont know which number it is. Is there a way to retun the value of the element by firing an onclick event for example when clicking the element??

thanks

chump2877
Jan 29th, 2007, 03:19 PM
Give each form element a name or id, and then you wont have that problem....

Or you can iterate through the child elements of your form and test their values to find the element in question...

Depends on what you're doing...what are you doing?

And this code:


getElementbyid.forms[5].element[4].valueis all wrong...it's either:


document.getElementById('yourID').valueor


document.forms[5].elements[4].valueas far as I know (regarding the second one..)