Coder1010
Coder1010

Reputation: 29

implement select all check boxes functionality in asp using javascript

I have a table which displays students record in asp.Now a column in that table contains a check box and also a functionality to check all the check boxes would be provided at the top. How to do that using javascript?

Upvotes: 0

Views: 657

Answers (2)

Kishor Kundan
Kishor Kundan

Reputation: 3165

define a link anywhere, grab its event and use checked property

<a href="#" rel="checkedBoxes">Check All Boxes</a>
<a href="#" rel="uncheckedBoxes">Uncheck all Boxes</a>

<script>
   $(function() {
      $("a[rel=checkedBoxes]").live("click", function(eV) {
          eV.preventDefault();
          $("form input:checkbox").attr("checked", "checked");
      }
      $("a[rel=uncheckedBoxes]").live("click", function(eV) {
          eV.preventDefault();
          $("form input:checkbox").attr("checked", "");
      }

   });
</script>

Upvotes: 0

Sender
Sender

Reputation: 6858

see demo

$(function(){

    // add multiple select / deselect functionality
    $("#selectall").click(function () {
          $('.case').attr('checked', this.checked);
    });

    // if all checkbox are selected, check the selectall checkbox
    // and viceversa
    $(".case").click(function(){

        if($(".case").length == $(".case:checked").length) {
            $("#selectall").attr("checked", "checked");
        } else {
            $("#selectall").removeAttr("checked");
        }

    });
});​

Upvotes: 1

Related Questions