Meaningless Drivel is fun!*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Return item in array" Watch "Return item in array" New topic
Author

Return item in array

N D Fisher
Greenhorn

Joined: Jun 01, 2007
Posts: 27
Hi,

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(this.id'), but it still doesn't return the index number.

How would I go about doing that?


Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.

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

Joined: Jun 01, 2007
Posts: 27
OK thanks, I'll give that a try.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Return item in array
 
Similar Threads
HashMap problem
recursion find number of times int appears in array...
Dynamic text fields gives java.lang.IndexOutOfBoundsException
using OGNL
Get selected object name or index