HI i have a group of radio buttons i want to get the value of selected radio button using jquery below is the code how i am doing but i am not able to get the value.
you should view source to understand what the radio list geerates for html. usually its a span with the ClientId, then a radio buttons, with a name = UniqueID. so you want:
var checkedvalue = $('#<%=radio.ClientID%> input:checked').val(); // note space after id, as you want the checked children
bruce (sqlwork.com)
Marked as answer by nrk_hi on Jun 26, 2012 03:23 PM
Because what you are using are asp controls you cannot search the RadioList by ID's directly as they are appended with content palceHolders. So to make it work you can try something like this
<script type="text/javascript">
var checkedvalue = $('[ID$="radio"]').find('input[type="radio"]:checked').val();
alert(checkedvalue);
</script>
OR
<script type="text/javascript">
var checkedvalue = $('<%= radio.ClientID %>').find('input[type="radio"]:checked').val();
alert(checkedvalue);
</script>
JQuery
Marked as answer by nrk_hi on Jun 26, 2012 03:23 PM
nrk_hi
Member
136 Points
110 Posts
how to get the value or text of of a radio button if i have multiple radio buttons
Jun 25, 2012 03:20 PM|LINK
HI i have a group of radio buttons i want to get the value of selected radio button using jquery below is the code how i am doing but i am not able to get the value.
Jquery:- <script type="text/javascript"> var checkedvalue = $('[ID="radio"]:checked').val(); alert(checkedvalue); </script> <asp:radiobuttonlist ID="radio" runat="server"> <asp:ListItem Text="apple" Selected="True"></asp:ListItem> <asp:ListItem Text="redapple"></asp:ListItem> <asp:ListItem Text="graps"></asp:ListItem> </asp:radiobuttonlist>can any one pls help me on this
JQuery
bruce (sqlwo...
All-Star
36822 Points
5441 Posts
Re: how to get the value or text of of a radio button if i have multiple radio buttons
Jun 25, 2012 03:34 PM|LINK
you should view source to understand what the radio list geerates for html. usually its a span with the ClientId, then a radio buttons, with a name = UniqueID. so you want:
var checkedvalue = $('#<%=radio.ClientID%> input:checked').val(); // note space after id, as you want the checked children
sushanth009
Contributor
6243 Points
1168 Posts
Re: how to get the value or text of of a radio button if i have multiple radio buttons
Jun 25, 2012 04:52 PM|LINK
Because what you are using are asp controls you cannot search the RadioList by ID's directly as they are appended with content palceHolders. So to make it work you can try something like this
<script type="text/javascript"> var checkedvalue = $('[ID$="radio"]').find('input[type="radio"]:checked').val(); alert(checkedvalue); </script> OR <script type="text/javascript"> var checkedvalue = $('<%= radio.ClientID %>').find('input[type="radio"]:checked').val(); alert(checkedvalue); </script>JQuery
vijayst
All-Star
16558 Points
3216 Posts
Microsoft
Re: how to get the value or text of of a radio button if i have multiple radio buttons
Jun 26, 2012 04:24 AM|LINK
The HTML translation of the radiolist is shown below:
In the above code, MainContent is the content placeholder id.
So, the selector is either $('input[type=radio]:checked') -- if these are the only radio buttons in the form
or $('input[id*=radio]:checked') . Here id*=radio means "id contains radio".
JQuery
http://liteblog.codeplex.com