I want to add a function to OnChange event of textbox at runtime (on page load). But if there is already a function define at onchange event of the particular textbox then I need to make sure the both function get a call at onchange event. How can I achieve that?
I am using IE7.
1 Answer
You can use the addEventListener function on that textbox
var tb = document.getElementById("textbox");
tb.addEventListener("change", function(evt) {
alert(tb.value);
}, false);
But for older versions of IE (IE6), this will not work. For that you can use the addEvent
1 Comment
kroiz
addEventListener has a third argument which is only optional in recent browser (since FF 6). You should provide that parameter for broadest compatibility. That argument determines whether to capture (true) the event or to let it propagate upward (false). Check out the function reference at developer.mozilla.org/en/DOM/element.addEventListener