[Element Indexes] How to determine current element index?

wxdqz

New Member
Hi everybody,

I have this sample code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Page</title>
</head>
<body>
<table border="1">
<tr>
<td>
Line 1
</td>
<td>
<input id="item" name="item" value=http://www.webdeveloper.com/forum/archive/index.php/"1">
</td>
<td>
<button id="btn_go" name="btn_go">Go</button>
</td>
</tr>
<tr>
<td>
Line 2
</td>
<td>
<input id="item" name="item" value="2">
</td>
<td>
<button id="btn_go" name="btn_go">Go</button>
</td>
</tr>
<tr>
<td>
Line 3
</td>
<td>
<input id="item" name="item" value="3">
</td>
<td>
<button id="btn_go" name="btn_go">Go</button>
</td>
</tr>
</table>
</body>
</html>


What I want to accomplish:
The Go buttons as well as the input boxes is a series that the the same id's and names. Is there any way that the Go buttons, by clicking on them, can detect their current index. What I mean, is there a way that (by the onclick event) the button that you clicked on can say "Hey! I am button number 2!". This will be a dynamic list that comes from a database. The current way that I am doing it is to pass a counter to a function in the onclick handler of the button that will tell its index, but I am sure tthat there must be a more elegant way to do it in javascript?

Thank you in advance for you ideas.

Peace.
--jaco
 
Top