You are here: irt.org | FAQ | JavaScript | Form | 3.1 | Q1143 [ previous next ]
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>