Java script
i m using a radioButtonList in asp.net web form, now i want to get selectedvalue of checked radio button,i used following code
var radio=document.getElementsByName("<%=rdoListSearchOrder.ClientID %>") [0].checked;
but i m getting 'undefined'
what's the wrong in my code thnaks

Purushottam RathoreRank #120 · 18.2K reputationPosted Jul 13, 2009, 12:47 AM EDT
Subramanyam RompicherlaRank #4,887 · 320 reputationPosted Jul 13, 2009, 1:55 AM EDT
function getSelectedRadio(buttonGroup) {
// returns the array number of the selected radio button or -1 if no button is selected
if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
for (var i=0; i
return i
}
}
} else {
if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
}
// if we get to this point, no radio button is selected
return -1;
} // Ends the "getSelectedRadio" function
function getSelectedRadioValue(buttonGroup) {
// returns the value of the selected radio button or "" if no button is selected
var i = getSelectedRadio(buttonGroup);
if (i == -1) {
return "";
} else {
if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
return buttonGroup[i].value;
} else { // The button group is just the one button, and it is checked
return buttonGroup.value;
}
}
} // Ends the "getSelectedRadioValue" function
ishika singh17 reputationPosted Jul 13, 2009, 3:49 AM EDT
ArshadRank #2,492 · 564 reputationPosted Jul 13, 2009, 4:41 AM EDT
document.getElementsById("rdoListSearchOrder").checked
because the way you are trying to use that does bind the value at the runtime but that time control doesnot exist thats y. i think its not very clear.
you can also use your old code this
document.getElementsByName("<%=rdoListSearchOrder.ClientID %>") [0].checked
after the body tag.
Cause: before loading the asp.net content(or body tag) you are using the the Control in the Head tag, thats y nothing is coming. you can write your javascript function after the body tag that time it will work.
Regards
Arshad.
ishika singh17 reputationPosted Jul 13, 2009, 9:45 PM EDT