File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Return item in array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Return item in array" Watch "Return item in array" New topic

Return item in array

N D Fisher

Joined: Jun 01, 2007
Posts: 27

I have an array of buttons on my web page, and when any one of them is clicked on I need to find out what the array index of that button actually is. So for example, you could have an 'onclick' function in each button so that when you click on it it shows an alert like, 'You clicked on button number 2', etc...

I've tried doing stuff like 'alert('), but it still doesn't return the index number.

How would I go about doing that?

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
JavaScript has no clue what index of the form array a form element is.

You could do a loop through the buttons

you would just have to send this to that function.

[ June 01, 2007: Message edited by: Eric Pascarello ]
N D Fisher

Joined: Jun 01, 2007
Posts: 27
OK thanks, I'll give that a try.
I agree. Here's the link:
subject: Return item in array
It's not a secret anymore!