Man do I hate IE.
You’d think that creating a radio button in javascript would be as easy as something like this:
var radioButton = document.createElement('input');
radioButton.id = 'RadioButtonList_1';
radioButton.name = 'RadioButtonList';
radioButton.type = 'radio';
parentElement.appendChild(radioButton);
but, no – that doesn’t work, thanks to IE not allowing the name attribute to be set for dynamically created elements.
So, instead, you need to do something like this:
var radioButton;
try {
// This is the only way you can set the "name" attribute in IE, but it will fail in other browsers
radioButton = document.createElement('<input id="RadioButtonList_1" name="RadioButtonList" type="radio" />');
} catch() {
// The above will fail if not in IE, so try it the correct way here
radioButton = document.createElement('input');
radioButton.id = 'RadioButtonList_1';
radioButton.name = 'RadioButtonList';
radioButton.type = 'radio';
}
Once again windows telling us what to do.
It’s just IE keeping it interesting.
Thanks it is working. When will the day come when the IE is not exist anymore!! IE is sucks!
I found that adding an onclick() to the radio button that sets radioButton.checked will also work in IE, although if you do that, you also need to add code to uncheck any other selected button in the group, since IE will not do that for you.