I have a function like this:
function doSomething()
{
// do something with select element
}
document.getElementById("selectel").onchange = doSomething;
// Call onchange event
document.getElementById("selectel").onchange();
Now, I recognize that I could call the function directly and pass a parameter. But I’d like to know if it’s possible to pass a parameter to the onchange() event handler after it’s evoked. I tried
document.getElementById("selectel").onchange("hello");
, but this didn’t work.
Thank you for your help.
You need to bind a parameter to your function. I’m going to copy paste a function from Ext-JS that lets you do just that. Warning: not for beginners
You can use it like
When your handler is called, additional parameters are appended to the arguments passed by the event handler (the event object).
There’s a lot of meat in this function, so feel free to ask any additional questions.
Here’s a jsfiddle to see it in action http://jsfiddle.net/yBhG6/