vendredi 8 décembre 2017

Unselect the select all checkbox when one of the other checkboxes is unselected

I iterate through an array to create some checkboxes, like below:

<div class="funnels">
    <label class="checkbox-inline">
    <input type="checkbox" id="selectall"> onClick="selectAll(this)" />All funnels
    </label>
    <?php foreach ($funnels as $funnel) { ?>
        <label class="checkbox-inline">
        <input type="checkbox" name="funnel[]" id ="funnel" value="<?php echo $funnel ?>" ><?php echo $funnel ?>
        </label>
    <?php } ?>
</div>

I use the following javascript to select all checkboxes when the All checkbox has been clicked. What I need to do is to unselect the all checkbox once one of the other checkboxes has been unchecked. Any help would be appreciated.

  function selectAll(source) {
         checkboxes = document.getElementsByName('funnel[]'); 
                for(i=0;i<checkboxes.length;i++)
                checkboxes[i].checked = source.checked;
    }




Aucun commentaire:

Enregistrer un commentaire