mercredi 27 mai 2015

Checkbox - Getting multiple check boxes checked on checking only one

I am trying to implement a check box which checks all the check boxes on the page. But when I changed the code slightly, it stopped working. I want to keep the changed code and still want the functionality to be working. Kindly help! * Kindly ignore the missing tags if any. It is correct unless I made mistake in editing the question.

   <script>     
    function toggle(source) {
        checkboxes = document.getElementsByName('qchecked[]');
        for(var i=0, n=checkboxes.length;i<n;i++){
            checkboxes[i].checked = source.checked;
        }
    }
</script>
<html> 
/* Code for the check box which when checked, checks all the checkbox. */
<input type='checkbox' class='css-checkbox' id='checkbox' onClick='toggle(this)'/>
<label for='checkbox' class='css-label lite-y-green'></label>



    /* Code for the check boxes which should be checked when the check box with id=checkbox is checked. 
I changed the code from INITIAL CODE to CHANGED CODE for some other purpose and the toggle stopped working. 
Now clicking on that one check box is not marking or un marking all the check boxes. */

    <!-- INITIAL CODE -->
    <input type='checkbox' id='yes_checkbox[$index]' class='css-checkbox' name='qchecked[]'/>
    <label for='yes_checkbox[$index]' class='css-label lite-y-green'></label>

    <!-- CHANGED CODE -->
    <input type='checkbox' id='yes_checkbox[$index]' class='css-checkbox' name='qchecked[$array6[qID]]'/>
    <label for='yes_checkbox[$index]' class='css-label lite-y-green'></label>
    </html>




Aucun commentaire:

Enregistrer un commentaire