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.
If you pass 'this' to your event handler function, then you no longer
need to know the index for your form. Because 'this' will become a
reference to your form element that you've clicked on.
For more information, do a search for the javascript keyword this.
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);" >