faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

How do I Retrieve an item(#) number without looping?

Jul 3rd, 2002 16:03
C Orchard,


Retreiving an item() number without looping?


I need to retreive a page item number without looping so I can 
reference it. I currently have code set up like this, but it can take 
upwards of 45 seconds to process if there are a lot of items on the 
page:

function CalClick(theObject){
  for(var i=0;i<99999;i++)
    if(theObject==document.all.item(i))
      return i;
    return -1;
}

<img src="some.gif" onClick="alert(CalClick(this));">

Is there a way I can pass the object item number straight from the item?
I would specify the item name (<img src="some.gif" name="a" 
onClick="alert(CalClick('a'));">), or hard code the number in the 
object (<img src="some.gif" onClick="alert(CalClick(12));">), but I am 
relying on repeating/copying this onClick code throughout the page and 
need it to automatically know what item is was referenced/clicked from.

Cheers,

C.