I would like to know how can I get the form element index when the
onclick event fire.
When the element is clicked, iterate through the form elements until
you find that element's ID. If you don't want to use ID, you could use
any other unique property value.
function getIndex(formEl) {
for( var x=0; x< myForm.length; x++) {
if (myForm[x].id == formEl.id) alert( "The index of this element
is " + x );
}
}
Then your HTML would be something like:
< input id="foo" onclick="getIndex(this);" >
Cylix wrote:
I have a form that contains around 20 input elements,
they have some onclick event on it.
I would like to know how can I get the form element index when the
onclick event fire.
I found no property or method to do so.
Thank you.