Hi all,
I was wondering if anyone can post an example of how to get aselected radio button option from an asp.net radio button list control via jquery on the loading of a page.
Thanks
Hi all,
I was wondering if anyone can post an example of how to get aselected radio button option from an asp.net radio button list control via jquery on the loading of a page.
Thanks
In your javascript function where you want to query the list, use this code..
var selected = jQuery('#<%= MyRadioButtonList.ClientID %> input:checked').val();
// or ...
var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val();
to set a sample label with the results of your selected radiobuttonlist, you could do this...
$(document).ready(function(){
var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val();
$("#<%= MySampleLabel.ClientID %>").text(selected);
}
Working example here.
The selector I used to get the radio buttons will grab all the radio buttons with the class ofinterest
on the page.
$(function(){
var value = $('input.ofinterest:checked').val();
$('#result').text(value);
});
If you want to scope the selector further, and you don't mind writing your JS directly in your aspx/ascx, you can use Scott's solution above instead. But if you give the buttons you're interested in a known classname, you can put this JS in a .js file.