Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Q1143 How can I get the elements index number of a form field using 'this'?

You are here: irt.org | FAQ | JavaScript | Form | 3.1 | Q1143 [ previous next ]


<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) {

<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)">

©2018 Martin Webb