Monday, June 3, 2024
85
rated 0 times [  87] [ 2]  / answers: 1 / hits: 119429  / 12 Years ago, mon, march 19, 2012, 12:00:00

I have created a checkbox dynamically. I have used addEventListener to call a function on click of the checkbox, which works in Google Chrome and Firefox but doesn't work in Internet Explorer 8. This is my code:



var _checkbox = document.createElement(input);
_checkbox.addEventListener(click, setCheckedValues, false);


setCheckedValues is my event handler.


More From » internet-explorer-8

 Answers
12

Try:



if (_checkbox.addEventListener) {
_checkbox.addEventListener(click, setCheckedValues, false);
}
else {
_checkbox.attachEvent(onclick, setCheckedValues);
}


Update::
For Internet Explorer versions prior to IE9, attachEvent method should be used to register the specified listener to the EventTarget it is called on, for others addEventListener should be used.


[#86749] Saturday, March 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
havenkamis

Total Points: 172
Total Questions: 93
Total Answers: 103

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;