Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  131] [ 4]  / answers: 1 / hits: 78254  / 16 Years ago, mon, february 23, 2009, 12:00:00

I have an ASP.NET web page with a databound RadioButtonList. I do not know how many radio buttons will be rendered at design time. I need to determine the SelectedValue on the client via JavaScript. I've tried the following without much luck:



var reasonCode = document.getElementById(RadioButtonList1);
var answer = reasonCode.SelectedValue;


(answer is being returned as undefined)
Please forgive my JavaScript ignorance, but what am I doing wrong?



Thanks in advance.


More From » asp.net

 Answers
23

ASP.NET renders a table and a bunch of other mark-up around the actual radio inputs. The following should work:-



 var list = document.getElementById(radios); //Client ID of the radiolist
var inputs = list.getElementsByTagName(input);
var selected;
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked) {
selected = inputs[i];
break;
}
}
if (selected) {
alert(selected.value);
}

[#99938] Tuesday, February 17, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parker

Total Points: 259
Total Questions: 109
Total Answers: 97

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;