Determining which object fired event from event handler. 
Author Message
 Determining which object fired event from event handler.

Greetings,

Please see if you can help me with this one:

//I create an img element
var o = document.createElement("img");

//Then I assign an event handler it's onclick event
o.onclick = itemClicked;

//And finally, I append the new element to the body
document.body.appendChild(o);

This all works very fine. My problem is this:
Suppose I add another img element, and assign that ones onclick event to the
same event handler. How will I be able to determine which object has been
clicked?

 function itemClicked()
{
    alert("How do I know which object has been clicked from here?");

Quote:
}

I need to get this to work in both IE5+ and NS6+.
Grateful for any help!

--

Thanks

/Billy



Tue, 29 Mar 2005 04:16:54 GMT  
 Determining which object fired event from event handler.
IE
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/...
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj...

NS
http://www.mozilla.org/docs/dom/domref/dom_event_ref24.html
http://www.mozilla.org/docs/dom/domref/dom_event_ref.html

--
If we knew what it was we were doing, it would not be called research, would
it? -Albert Einstein

=-=-=
Steve
-=-=-


Quote:
> Greetings,

> Please see if you can help me with this one:

> //I create an img element
> var o = document.createElement("img");

> //Then I assign an event handler it's onclick event
> o.onclick = itemClicked;

> //And finally, I append the new element to the body
> document.body.appendChild(o);

> This all works very fine. My problem is this:
> Suppose I add another img element, and assign that ones onclick event to the
> same event handler. How will I be able to determine which object has been
> clicked?

>  function itemClicked()
> {
>     alert("How do I know which object has been clicked from here?");
> }

> I need to get this to work in both IE5+ and NS6+.
> Grateful for any help!

> --

> Thanks

> /Billy



Tue, 29 Mar 2005 07:07:11 GMT  
 Determining which object fired event from event handler.
Excellent, thank you very much!

/Billy



Quote:
> IE

http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/...
ent.asp
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj....
asp
Quote:

> NS
> http://www.mozilla.org/docs/dom/domref/dom_event_ref24.html
> http://www.mozilla.org/docs/dom/domref/dom_event_ref.html

> --
> If we knew what it was we were doing, it would not be called research,
would
> it? -Albert Einstein

> =-=-=
> Steve
> -=-=-



> > Greetings,

> > Please see if you can help me with this one:

> > //I create an img element
> > var o = document.createElement("img");

> > //Then I assign an event handler it's onclick event
> > o.onclick = itemClicked;

> > //And finally, I append the new element to the body
> > document.body.appendChild(o);

> > This all works very fine. My problem is this:
> > Suppose I add another img element, and assign that ones onclick event to
the
> > same event handler. How will I be able to determine which object has
been
> > clicked?

> >  function itemClicked()
> > {
> >     alert("How do I know which object has been clicked from here?");
> > }

> > I need to get this to work in both IE5+ and NS6+.
> > Grateful for any help!

> > --

> > Thanks

> > /Billy



Tue, 29 Mar 2005 16:02:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Add an event handler to the actual event handler for an element

2. Referencing document object of IFrame object in event handler

3. fire keyboard events form an onclick page event

4. ATL COM Component firing events into VBScript event sink

5. JScript event handler for ActiveX DLL events within IE

6. onchange event/event handler not triggering

7. Object in ASP page not firing events

8. Cloned tbody object refuses to fire onclick event (addendum to previous post)

9. Handling events fired from an ATL COM object in VBScript

10. Problem with reassigning an object's event handlers

11. Capturing the object that fires the OnBeforeUnload event of the window

12. Scripted event handlers in objects cont'd

 

 
Powered by phpBB® Forum Software