How can I determine the SelectedValue of a RadioButtonList in JavaScript?
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); }
Try this to get the selected value from the RadioButtonList.
var selectedvalue = $('#<%= yourRadioButtonList.ClientID %> input:checked').val()
I always View Source. You will find each radio button item to have a unique id you can work with and iterate through them to figure out which one is Checked.
Edit: found an example. I have a radio button list rbSearch. This is in an ascx called ReportFilter. In View Source I see
ReportFilter1_rbSearch_0ReportFilter1_rbSearch_1ReportFilter1_rbSearch_2
So you can either loop through document.getElementById("ReportFilter1_rbSearch_" + idx ) or have a switch statement, and see which one has .checked = true.