Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Discussion on select and unselect all check box on click.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 360
    Comment on it

    Hi Reader's,
    Welcome to FindNerd,today we are going to discussion on select and unselect all check boxes on a click.

    If we want to select all check boxes in your web application, so we have to follow below process:

    Firstly we have to make a view in Html to show check boxes and also put a button for selecting all check boxes together just on a single click and also remove the selection on a single click.

    you can see below view in Html

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <title>Check Boxes</title>
    5. <!-- Include JS File Here -->
    6. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    7. </head>
    8. <body>
    9. <h1>Select and Unselect Check Box</h1>
    10. <div class="button">
    11. <input class="check" id="Item 1" name="option1" type="checkbox">
    12. <label class="label1" for="Item 1">Box 1</label>
    13. <input class="check" id="Item 2" name="option1" type="checkbox">
    14. <label class="label1" for="Item 2">Box 2</label>
    15. <input class="check" id="Item 3" name="option1" type="checkbox">
    16. <label class="label1" for="Item 3">Box 3</label>
    17. <input class="check" id="Item 4" name="option1" type="checkbox">
    18. <label class="label1" for="Item 4">Box 4</label>
    19. </div><br>
    20. <input id="checkAll" type="button" value="Submit ">
    21. </body>
    22. </html>

    This is Html part in which we can see there are four check boxes and a button.

    Now we have to write Javascript code for functionality to select all and unselect all just click on submit button.

    you can see below code for better understanding

    1. <script>
    2. $(document).ready(function(){
    3. // Below code is used to remove all check property with class check options.
    4. $(".check").click(function() {
    5. $("#checkAll").attr("data-type", "uncheck");
    6. });
    7. // Below code is used to remove all check property with name=option2 options
    8. $("input[name=option2]").click(function() {
    9. $("#selectall").prop("checked", false);
    10. });
    11.  
    12. // JS for Check/Uncheck all CheckBoxes by Button //
    13. $("#checkAll").attr("data-type", "check");
    14. $("#checkAll").click(function() {
    15. //check condition here
    16. if ($("#checkAll").attr("data-type") === "check") {
    17. $(".check").prop("checked", true);
    18. $("#checkAll").attr("data-type", "uncheck");
    19. }else{
    20. $(".check").prop("checked", false);
    21. $("#checkAll").attr("data-type", "check");
    22. }
    23. })
    24.  
    25. });
    26.  
    27. </script>

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: