Wednesday, 17 August 2016

Get and Set Selected Text and Value of RadioButtonList using JavaScript or jQuery in ASP.Net

Get and Set Selected Text and Value of RadioButtonList using jQuery in ASP.Net
Description:

In this example we explain that how to Get or set the Text /value of the RadioButtonList using JavaScript and jQuery in asp.net.or get or set the selected Text and Value pair of the radioButtonList using JavaScript or jQuery.

Here below is the example of list of the Game defines with RadioButtonList and when you click on submit button it will display the alert message with the selected Text and value of the radioButtonList using client side JavaScript and jQuery.
GetSetRadioButtonListValue.aspx:

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

<!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">
    <title>Get and Set Selected Text and Value of RadioButtonList using jQuery in ASP.Net
    </title>
    <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*=btnFetch]").click(function () {
                var checked_radio = $("[id*=rblGame] input:checked");
                var value = checked_radio.val();
                var text = checked_radio.closest("td").find("label").html();
                alert("You Have selected Text =  " + text + " AND  Value =  " + value);
                return false;
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:RadioButtonList ID="rblGame" runat="server">
        <asp:ListItem Text="Cricket" Value="1" />
        <asp:ListItem Text="Hockey" Value="2" />
        <asp:ListItem Text="Tennis" Value="3" Selected="True" />
    </asp:RadioButtonList>
    <asp:Button ID="btnFetch" Text="Fetch Selected Text/Value" runat="server" />
    </form>
</body>
</html>



0 comments:

Post a Comment