Reputation: 4366
I'm try to use jQuery to check whether or not a particular element in a RadioButtonList is selected. In the past I've used Control.ClientID to get the HTML ID of the element, but this just gives the ID of the whole list. I'd like to get the ID of a particular element in the list so I can see if it is checked or not.
Basically I have:
<asp:RadioButtonList ID="AttendedStudySessions" runat="server">
<asp:ListItem Value="True">Yes</asp:ListItem>
<asp:ListItem Value="False">No</asp:ListItem>
</asp:RadioButtonList>
Which generates:
<tr>
<td><input type="radio" value="True" name="ctl00$ctl00$MainContent$MainContent$AttendedStudySessions" id="ctl00_ctl00_MainContent_MainContent_AttendedStudySessions_0"><label for="ctl00_ctl00_MainContent_MainContent_AttendedStudySessions_0">Yes</label></td>
</tr>
<tr>
<td><input type="radio" value="False" name="ctl00$ctl00$MainContent$MainContent$AttendedStudySessions" id="ctl00_ctl00_MainContent_MainContent_AttendedStudySessions_1"><label for="ctl00_ctl00_MainContent_MainContent_AttendedStudySessions_1">No</label></td>
</tr>
And I want to be able to check whether one of those has been selected using something similar to this:
jQuery('#<%= AttendedStudySessions.Items.GetByValue("False").UniqueID %>').prop('checked');
But obviously, that doesn't work :)
Upvotes: 0
Views: 126
Reputation: 1518
This will return the checked value, or null if none is checked:
$('input[type="radio"][name*="<%= AttendedStudySessions.UniqueID %>"][checked="checked"]').val()
Upvotes: 0
Reputation: 69905
Try this
if($("input[name*=AttendedStudySessions]:checked").length > 0){
//The radio button is checked
}
Upvotes: 1
Reputation: 26
Something like this:
var id = $("input[@name=radioGroup]:checked").attr('id');
?
Upvotes: 1