top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I set all checkboxes to true by clicking on a Single checkbox?

0 votes
386 views
How can I set all checkboxes to true by clicking on a Single checkbox?
posted Jul 4, 2014 by Amritpal Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

It can be done using Javascript. The Code goes Here:

<script >
function checkall(source) {
  var checkboxes=new Array();
  checkboxes= document.getElementsByTagName('input');
  for(var i=0;i<checkboxes.length;i++)
  {
    if(checkboxes[i].type=='checkbox')
    {
      checkboxes[i].checked = source.checked;
    }
  }
}
</script>

<input type="checkbox" onClick="checkall(this)" /> Check All

<input type="checkbox" name="foo[]" value="1">  1
<input type="checkbox" name="foo[]" value="2">  2
<input type="checkbox" name="foo[]" value="3">  3
<input type="checkbox" name="foo[]" value="4">  4
answer Jul 8, 2014 by Rahul Mahajan
...