Sunday, 30 April 2017

how to get selected radio button text in jQuery.


how to get selected radio button text in jQuery.
Description:
in this example we explain that how to Get and set the Selected Text of RadioButtonList instead of value using jQuery in asp.net or how to get the text of the radio button instead of value using jQuery.

In previous example we explain that how to get the selected dropdown list text instead of value using jQuery. Here we demonstrate how to get and set the selected Text and Value of RadioButtonList using jQuery in asp.net.
Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Radiogetset.aspx.cs" Inherits="Radiogetset" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("[id*=btnGetText]").click(function () {
                var checked_radio = $("[id*=rblGames] input:checked");
                var value = checked_radio.val();
                var text = checked_radio.closest("td").find("label").html();
                alert("Text: " + text + " Value: " + value);
                return false;
            });
        });
    </script>
    <title>Get and Set Selected Text and Value of RadioButtonList using jQuery in ASP.Net
    </title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:RadioButtonList ID="rblGames" runat="server">
        <asp:ListItem Text="Cricket" Value="1" />
        <asp:ListItem Text="Tennis" Value="2" />
        <asp:ListItem Text="Hockey" Value="3" Selected="True" />
        <asp:ListItem Text="volleyball" Value="4" />
    </asp:RadioButtonList>
    <asp:Button ID="btnGetText" Text="Get Selected Text" runat="server" />
    </form>
</body>
</html>




0 comments:

Post a Comment