0

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?

1
  • post your mark up for table and checkbox. Commented Sep 7, 2012 at 5:25

2 Answers 2

1

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");
        }

    });
});​
Sign up to request clarification or add additional context in comments.

2 Comments

Actually my values are coming from a database and in your example the values are statically bound.Means for each database field a new check box will be displayed corresponding to it.How to get the value of that?
so you want to in asp.net see this link
0

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>

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.