Reputation: 1832
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>
Upvotes: 8
Views: 20295
Reputation: 102448
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
Upvotes: 4
Reputation: 3775
$('#<%=rdlMinor.ClientID %>').change(function() {
if($('#<%=rdlMinor.ClientID %> input:checked').val() == 'Yes')
{
$('#<%=rdlJoint.ClientID %>').find("input[value='Yes']").attr("checked", "checked");
}
});
Upvotes: 11