How to pass the event object when dynamically attaching an event handler in NS6
Hi;
I have a question regarding passing the event object in NS6 hopefully someone can clarify. I have a function that has a few parameters, one of which is the event object. I wish to dynamically assign this function to an event handler, which itself is attached to a HTML element using script. My question is, how do I pass the event object into this function in this case? The below should work, but it doesn't:
The above returns an "event" not defined error. I have no problem getting things to work if I simply defined the event handler using HTML. For example, the below works:
What still throws me off is why when you attach event handlers using HTML, you need to pass in "event", and not a name holder like e or "ewhateveryouwant", but in the above case, "e' instead in NS6. Specifically, I'm talking about "e" as it occurs here:
dothis(5, 10, e);
I guess my question really boils down to how parameters in anonymous functions operate.
In IE4+, all this is much simplier, as there's simply "event" to deal with.
__________________
- George
- JavaScript Kit- JavaScript tutorials and 400+ scripts!
- JavaScript Reference- JavaScript reference you can relate to.
Every time an event fires, the event object is a unique object. It makes more sense to me to pass this as an argument to the event listener every time, rather than pollute the global namespace with variables which really are better implemented elsewhere.
BTW, this lets you create your own event objects and dispath them programatically without fear of altering the global event object via document.createEvent() and the various initEventType() methods.