• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How do I attach events with arguments to runtime element?

lozina

Lifer
I am working on a dynamic page which creates an element then needs to attach an event to it.

As an example, this is what I did to make a drop down:

el= document.createElement('select');
el.setAttribute('onchange', 'doSomething(this)');

and this works fine in Firefox, but does not work in IE.

What's the simplest way I can get this to work in IE?
 
I guess IE just does not compile new events at runtime, unless it is something like this:

element.onchange = doSomething;

That and attachEvent seems to be the ONLY way I can add an event to an element, and the drawback to either is of course I cannot pass any arguments.

I could do a little workaround, where the function "doSomething" refers to "this" to get at the element the triggered on, so I dont have to pass "this" as an argument. But what if I wanted to pass some other variables as an arugment? Impossible in IE, I suppose?

If anyone can shed some light on this for me I'd greatly appreciate it
 
Back
Top