I need to select a radio button dynamically.
i) I have created few radio buttons dynamically, i.e. in a function using:
function funcName()
{
Something.innerHTML = '<input type = "radio" name = "rName" id = "1" />' + '<input type = "radio" name = "rName" id = "2" />' + '<input type = "radio" name = "rName" id = "3" />';
}
ii) I need to select a radio button dynamically, in another function:
function funcNAme(someVar)
{
document.getElementById(someVar).checked = true;
}
But this does not work, i.e. the radio button doesn not get selected. However, ‘disabled’ works fine.
Also:
alert(someVar);
returns the appropriate desired value.
The syntax is as follows :
So you need to use
See here -> HTMLInputElement
Working example -> http://jsfiddle.net/p5yca/
And please please do not use numbers for IDs of elements -> http://www.w3.org/TR/html401/types.html#type-name