Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery get Selected Radio Button from List on page load

I was wondering if anyone can post an example of how to get a selected radio button option from an asp.net radio button list control via jquery on the loading of a page.

Thanks

like image 431
zSynopsis Avatar asked Jul 10 '09 15:07

zSynopsis


1 Answers

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);
}
like image 81
Scott Ivey Avatar answered Oct 20 '22 11:10

Scott Ivey