On Sat, 6 Mar 2004 20:16:18 +0100, Paweł <pm**@op.pl> wrote:
[snip]
What I ask about is how do we know that Nth element is Nth??
Let's say we have a row in the table, abd for each row we have
rowIndex...
I would like to have similiar property for Input element...
You mean you want to know the index of a particular form control when you
have a reference (and only a reference) to that control?
There's no direct method. You'll have to loop through all controls in the
form and check if the "mystery" reference matches a reference in the
elements collection:
function getIndex( obj ) {
var e = obj.form.elements, n = e.length;
for( var i = 0; i < n; ++i )
if( obj == e[ i ]) return i;
return null;
}
...
<form ...>
<input type="button" onclick="alert(getIndex(this))">
<input type="button" onclick="alert(getIndex(this))">
</form>
Clicking on the first button will display 0. Clicking the second will
display 1.
Is that better?
Mike
--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)