Wednesday, 8 October 2014

SELECT/DESELECT MULTIPLE CHECKBOXES USING Jquery

<HTML> 
<HEAD> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> 
<script type="text/javascript"> 
$('document').ready(function(){ 
      $("#selectall").click(function () { 
                $('.td').attr('checked', this.checked);
 alert("You have selected all boxes"); 
});
 
 $(".td").click(function(){ 
          alert("You have checked "+$(".td:checked").length+" boxes"); 
 
if($(".td").length == $(".td:checked").length) { 
          $("#selectall").attr("checked", "checked"); 
} else {
            $("#selectall").removeAttr("checked"); 
});
 }); 
</script>
 </HEAD> 
<BODY> 
<input type="checkbox" id="selectall"/><b>Subjects </b><br>
 <input type="checkbox" class="td" />Maths <br> 
<input type="checkbox" class="td" />History <br> 
<input type="checkbox" class="td" />Computer Science <br> 
<input type="checkbox" class="td" />Science <br> <
input type="checkbox" class="td" />Astrology <br> 
</BODY> 
</HTML>

0 comments:

Post a Comment