While working on the server side, I dynamically created radio buttons with the following code:
RadioButton button1 = new RadioButton();
button1.ID = question.Name + "_Radio1";
button1.Text = "Yes";
RadioButton button2 = new RadioButton();
button2.ID = question.Name + "_Radio2";
button2.Text = "No";
if (question.IsDynamic)
{
button1.Attributes.Add("onclick", "return updateQuestions('" + button1.ID + "')");
}
After this, when trying to retrieve the value of the radio button using JavaScript, the userAnswer variable was empty. How can I successfully obtain the value of the radio button?
function updateQuestions(controlName) {
var userAnswer;
if (controlType == "RadioButton") {
userAnswer = document.getElementById(controlName).innerHTML;
}