Tuesday, May 1, 2012

Get Text and Value of Selected Item of ASP.Net RadioButtonList using jQuery


[head>
 [script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
   [script type="text/javascript">
        $("#demo").live("click", function () {
            var selectedItem = $("[id*=RadioButtonList1] input:checked");
            if (selectedItem.length > 0) {
                alert("Selected Value: " + selectedItem.val() + " Selected Text: " + selectedItem.next().html());
            } else {
                alert("Please select an item.");
            }
        });
    [/script>
[/head>
[body>
    [form id="form2" runat="server">
    [asp:RadioButtonList ID="RadioButtonList1" runat="server">
        [asp:ListItem Text="One" Value="1" />
        [asp:ListItem Text="Two" Value="2" />
        [asp:ListItem Text="Three" Value="3" />
    [/asp:RadioButtonList>
    [br />
    [input type = "button" id = "Button1" value = "Demo" />
    [/form>
[/body>
[/html>