Checkboxes Count and set Parent Checkbox

[Total: 0    Average: 0/5]

If all child checkboxes are checked, then the parent is checked.

Head Code:

<script>
function checkIt(v)
{
  if(v==1)
  {
    var count=0;
    if(document.f1.c1.checked)count++;
    if(document.f1.c2.checked)count++;
    if(document.f1.c3.checked)count++;
    document.f1.p1.checked=(count==3);
  }
}
</script>

Body Code:

<form name=f1>
Parent:<input type=checkbox name=p1><BR>
Child 1<input type=checkbox name=c1 onchange="checkIt(1)"><BR>
Child 2<input type=checkbox name=c2 onchange="checkIt(1)"><BR>
Child 3<input type=checkbox name=c3 onchange="checkIt(1)"><BR>
</form>

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *