How do you get the checked value of asp:RadioButton with jQuery?

Dan Bailiff picture Dan Bailiff · Oct 9, 2009 · Viewed 27.7k times · Source

I need to do something like this:

<asp:RadioButton ID="rbDate" runat="server" Text="Date" GroupName="grpPrimary" />

and be able to check the value of the radio button's checked value in jQuery, but my attempts like these don't return true/false.

if ($('[name=rbDate]').attr("Checked"))

if ($('[name=rbDate]').attr("Checked").val())

if ($('[name=rbDate]:checked').val())

A little help?

Answer

ChaosPandion picture ChaosPandion · Oct 9, 2009

This is probably the easiest way to do it. The *= searches the whole id attribute for rbDate which takes care of the whole ASP.NET id mangling.

$('input[id*=rbDate]').is(":checked");