• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return item in array

 
N D Fisher
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK thanks, I'll give that a try.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic