Enable Disable CheckBoxList based on another using jQuery in ASP.Net

Last Reply 13 days ago By dharmendr

Posted 13 days ago

hello,

i have 2 checkbox list, i want javascript to hide CHECKBOXLIST 2 conditinally so if in checkbox list one Value "TWO" is checked so CHEKXBOXLIST 2 Visible true else visible false

Posted 13 days ago

Hi nauna,

Check this example. Now please take its reference and correct your code.

HTML

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("[id*=CheckBoxList1]").bind("click", function () {
            $("[id*=CheckBoxList2]").hide();
            if ($("[id*=CheckBoxList1] input:checked").length > 0) {
                $.each($("[id*=CheckBoxList1] input:checked"), function () {
                    if ($(this).val() == 'Two') {
                        $("[id*=CheckBoxList2]").show();
                    }
                });
            }
        });
    });
</script>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
    <asp:ListItem Text="One" Value="One" />
    <asp:ListItem Text="Two" Value="Two" />
</asp:CheckBoxList>
<br />
<asp:CheckBoxList ID="CheckBoxList2" runat="server" Style="display: none">
    <asp:ListItem Text="Mango" Value="Mango" />
    <asp:ListItem Text="Apple" Value="Apple" />
</asp:CheckBoxList>

Screenshot