Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net RadioButtonList: using jQuery to get the ListItem selected

have 2 RadioButtonLists:

Are you a minor?:  oYes  oNo
Do you wish a joint account?:  oYes  oNo

If the answer to the 1st question is yes, I want to detect the response to the first question and set the answer to the 2nd question to yes using a jQuery function. Thanks in advance.

<asp:Label ID="lblMinfor" CssClass="boldIt" runat="server" Text="Is this account for a minor" Style="float: left; width: 200px;"></asp:Label><br />
<asp:RadioButtonList ID="rdlMinor" runat="server" RepeatDirection="Horizontal" Width="130px" Style="float: left;" BorderStyle="None" RepeatLayout="Flow" ()>
    <asp:ListItem>Yes</asp:ListItem>
    <asp:ListItem Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
<asp:Label ID="lblJoint" CssClass="boldIt" runat="server" Text="Is this for a joint account?" Style="float: left; width: 200px;"></asp:Label><br />
<asp:RadioButtonList ID="rdlJoint" runat="server" RepeatDirection="Horizontal" Width="130px" Style="float: left;" BorderStyle="None" RepeatLayout="Flow">
    <asp:ListItem>Yes</asp:ListItem>
    <asp:ListItem Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
like image 827
Susan Avatar asked Feb 22 '12 21:02

Susan


2 Answers

$('#<%=rdlMinor.ClientID %>').change(function() {
    if($('#<%=rdlMinor.ClientID %> input:checked').val() == 'Yes') 
    {
        $('#<%=rdlJoint.ClientID %>').find("input[value='Yes']").attr("checked", "checked");
    }
});
like image 178
kevev22 Avatar answered Sep 20 '22 05:09

kevev22


Try this code:

<script type="text/javascript">

$(document).ready(function() {

    $("#<%=rdlMinor.ClientID%>").change(function()
    {
        var rbvalue = $("input[@name=<%=rdlMinor.ClientID%>]:radio:checked").val();

        if(rbvalue == "Yes")
        {
            $('#<%=rdlJoint.ClientID %>').find("input[value='Yes']").attr("checked", "checked");
        }
    });

});

</script>

More on these subjects:

JQuery Accessing the Client Generated ID of ASP.NET Controls

How to Set Get RadioButtonList Selected Value using jQuery

like image 23
Leniel Maccaferri Avatar answered Sep 24 '22 05:09

Leniel Maccaferri