Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
<script type="text/javascript">
    $('#checkallindus').click(function () {
        if($('#checkallindus').attr('checked',false)){
            $('.cat1').hide();
        }
    });
    $('#checkallpro').click(function () {
        if ($('#checkallpro').attr('checked', false)) {
            $('.cat2').hide();
        }
    });
    $('.checkall').click(function () {
        if ((document.getElementById('checkallindus').checked == false) &&                                      (document.getElementById('checkallprod').checked == false)) {
            $('.disp').hide();
        }
    });
</script>


HTML
<html>
<body>
    <div class="disp">
        Case 1
        <div class="cat1">Industry: Environment</div>
        <div class="cat2">Product: ASP.NET</div>
        <div class="des">The asp.net product in the envirnmen industry</div>
    </div>
    <div class="disp">
        Case 2
        <div class="cat1">Industry: Hobbyist</div>
        <div class="cat2">Product: WinRT</div>
        <div class="des">The Winrt product in the hobbyist industry</div>
    </div>
    <div class="disp">
        <div class="cat1">Industry: Hobbysit</div>
        <div class="cat2">Product: ASP.NET</div>
        <div class="des">The ASP.NET product in the hobbyist industry</div>
    </div>
    <div class="head">Industry</div>
    <input type="checkbox" id="checkallindus" checked/>ALL
    <input type="checkbox" class="checkindus" checked/>Environment
    <input type="checkbox" class="checkindus" checked/>Hobbyist
    <div class="head">Product</div>
    <input type="checkbox" id="checkallpro" checked/>ALL
    <input type="checkbox" class="checkpro" checked/>ASP.NET
    <input type="checkbox" class="checkpro" checked/>WinRT
       </body>
       </html>


In the code I have written the script for the "ALL" checkboxes but for indivual checkboxes I am unable to write the script. The content under "disp" must be hidden only if the checkbox under industry and also the corresponding checkbox under product is unchecked. Can anyone help me how to write the script in this case.
Posted

1 solution

I do not think you check all work. You have to sort up the naming of the classes for the various html elements, just one example:
1. rename the individual class="disp" to say disp1, disp2, and disp3 respectively;
2. rename the class="checkindus" for environment to say class="checkindusenvironment"
XML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){

    $('#checkallindus').click(function () {
       var $this = $(this);
       if ($this.is(':checked')) {
          $('.cat1').show();
       } else {
          $('.cat1').hide();
       }
    });

    $('.checkindusenvironment').click(function () {
       var $this = $(this);
       if ($this.is(':checked')) {
          $('.disp1 .cat1').show();
       } else {
          $('.disp1 .cat1').hide();
       }
    });

});
</script>
</head>
<body>
    <div class="disp1">
        Case 1
        <div class="cat1">Industry: Environment</div>
        <div class="cat2">Product: ASP.NET</div>
        <div class="des">The asp.net product in the envirnmen industry</div>
    </div>
    <div class="disp2">
        Case 2
        <div class="cat1">Industry: Hobbyist</div>
        <div class="cat2">Product: WinRT</div>
        <div class="des">The Winrt product in the hobbyist industry</div>
    </div>
    <div class="disp3">
        <div class="cat1">Industry: Hobbysit</div>
        <div class="cat2">Product: ASP.NET</div>
        <div class="des">The ASP.NET product in the hobbyist industry</div>
    </div>
    <div class="head">Industry</div>
    <input type="checkbox" id="checkallindus" checked>ALL
    <input type="checkbox" class="checkindusenvironment" checked >Environment
    <input type="checkbox" class="checkindushobbyist" checked >Hobbyist
    <div class="head">Product</div>
    <input type="checkbox" id="checkallpro" checked>ALL
    <input type="checkbox" class="checkpro" checked>ASP.NET
    <input type="checkbox" class="checkpro" checked>WinRT
</body>
</html>

The rest is your homework.
 
Share this answer
 
Comments
user 3008 19-May-14 2:52am    
Thank you for your reply. Here I have provided only a part of my code but I have nearly 50 cases. and 20 checkboxes in each catgory. In tha case it will not be possible to write indivual hide and show script for each cases. Is there any other solution for this? And moreover I haven't wrriten all the content in my html itslef. I have written the content in xml page and retieved in my view page using looping, so it will not be possible for me to provide indiviual name for each checkbox.
Peter Leow 19-May-14 2:58am    
I have already answered to your original question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900