Adding click event
Posted on 2006-07-12
I am trying to add a click event to a button that is created dynamically. I want the click event to trigger a function that takes a parameter.
The function I am trying to trigger could be as simple as :
alert("hello " + name);
and my dynamic button like:
var MyButton = document.createElement("INPUT");
MyButton.value = "Click Me";
MyButton.type = "Button";
In non-IE browsers I can use the setAttribute method like this:
but in IE I have to use the attachEvent method like this
My problem is HOW CAN I PASS THE NECESSARY PARAMETERS TO THE FUNCTION since the MyAlert function take the "name" parameter?
All help appreciated