|
Q1143 How can I get the elements index number of a form field using 'this'?
irt.org | Knowledge Base | JavaScript | Form 3.1 | Q1143 [ previous next ]
Q1143 How can I get the elements index number of a form field using 'this'?
Try:
<script language="JavaScript"><!--
function getIndex(what) {
for (var i=0;i<document.myForm.elements.length;i++)
if (what == document.myForm.elements[i])
return i;
return -1;
}
function test(what) {
alert(getIndex(what));
}
//--></script>
<form name="myForm">
<Input type="button" value="Button0" onClick="test(this)">
<input type="button" value="Button1" onClick="test(this)">
<input type="button" value="Button2" onClick="test(this)">
<input type="button" value="Button3" onClick="test(this)">
</form>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.