Home > ASP.Net, Jquery > Get the selected item value from RadiobuttonList using JQuery

Get the selected item value from RadiobuttonList using JQuery


Hi all,

Try this example to get the selected item value from RadiobuttonList using JQuery


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
//Attach click event to button
$('#Button1').click(function (e) {
//Get the selected item value from RadioButtonList
var rblSelectedValue = $("#<%= RadioButtonList1.ClientID %> input:checked").val();
$("#<%= lblSelectedValue.ClientID %>").text(rblSelectedValue);
//Get the selected item text value from RadioButtonList
var rblSelectedText = $("#<%= RadioButtonList1.ClientID %> input:checked").next().html();
$("#<%= lblSelectedItem.ClientID %>").text(rblSelectedText);
//Cancel the postback
e.preventDefault();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="1" Text="First"></asp:ListItem>
<asp:ListItem Value="2" Text="Second"></asp:ListItem>
<asp:ListItem Value="3" Text="Third"></asp:ListItem>
<asp:ListItem Value="4" Text="Fourth"></asp:ListItem>
<asp:ListItem Value="5" Text="Fifth"></asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" Text="Get Selected Value" />

Selected Value
<asp:Label ID="lblSelectedValue" runat="server" Text=""></asp:Label>

Selected Item
<asp:Label ID="lblSelectedItem" runat="server" Text=""></asp:Label>

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net, Jquery
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: