Reading the selected value from asp:RadioButtonList using jQuery Reading the selected value from asp:RadioButtonList using jQuery asp.net asp.net

Reading the selected value from asp:RadioButtonList using jQuery


The simple way to retrieve checked value of RadioButtonList1 is:

$('#RadioButtonList1 input:checked').val()

Edit by Tim:

where RadioButtonList1 must be the ClientID of the RadioButtonList

var rblSelectedValue = $("#<%= RadioButtonList1.ClientID %> input:checked"); 


this:

$('#rblDiv input').click(function(){    alert($('#rblDiv input').index(this));});

will get you the index of the radio button that was clicked (i think, untested) (note you've had to wrap your RBL in #rblDiv

you could then use that to display the corresponding div like this:

$('.divCollection div:eq(' + $('#rblDiv input').index(this) +')').show();

Is that what you meant?

Edit: Another approach would be to give the rbl a class name, then go:

$('.rblClass').val();


This worked for me...

<asp:RadioButtonList runat="server" ID="Intent">  <asp:ListItem Value="Confirm">Yes!</asp:ListItem>  <asp:ListItem Value="Postpone">Not now</asp:ListItem>  <asp:ListItem Value="Decline">Never!</asp:ListItem></asp:RadioButtonList>

The handler:

$(document).ready(function () {  $("#<%=Intent.ClientID%>").change(function(){   var rbvalue = $("input[name='<%=Intent.UniqueID%>']:radio:checked").val();   if(rbvalue == "Confirm"){    alert("Woohoo, Thanks!");   } else if (rbvalue == "Postpone"){    alert("Well, I really hope it's soon");   } else if (rbvalue == "Decline"){    alert("Shucks!");   } else {    alert("How'd you get here? Who sent you?");   }  });});

The important part:$("input[name='<%=Intent.UniqueID%>']:radio:checked").val();