Search code examples
asp.netjqueryradiobuttonlist

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


Solution

  • 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);
    }