1

I have 32 checkboxes (checkbox1,checkbox2,checkbox3.... checkbox32) and 32 div(div1,div2,div3.....div32) and one asp:Button.

On button click I need to make div1 visble if checkbox1 checked true and div2 visble if checkbox2 checked true and div3 visble if checkbox3 checked true and so on using JQuery..

<div class="CheckBoxDiv ">
        <asp:CheckBox ID="checkBox1" runat="server"  />

    </div>
        <asp:CheckBox ID="checkBox2" runat="server"  />

    </div>        .
                  .
                  .

<asp:Button ID="buttonShowData" runat="server" Text="Show data" class="ShowDataButton"  />

<div id="div1" runat="server" visible="false">
               ......
</div>
<div id="div2" runat="server" visible="false">
               ......
</div>
                    .
                    .
3
  • 2
    code/html or it didn't happen. Commented Dec 14, 2012 at 17:21
  • Nothing .. I am new to jquery... @ Explosion Pills Commented Dec 14, 2012 at 17:26
  • @Explosion Pills - I have added the code.. Commented Dec 14, 2012 at 17:43

1 Answer 1

3
$("button").on('click', function () {
    $(":checkbox").each(function (idx) {
       if ($(this).is(":checked")) {
          $("div").eq(idx + 1).show();
       }
       else {
          $("div").eq(idx + 1).hide();
       }
    });
});

This goes through all checkboxes and shows/hides corresponding divs from all available divs. It's highly likely that you'll want to use more specific selectors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.