Return to Snippet

Revision: 29404
at July 28, 2010 19:48 by chemical


Initial Code
<script type="text/javascript">
 
function toggle_checkboxes(id) {
    if (!document.getElementById){ return; }
    if (!document.getElementsByTagName){ return; }
    var inputs = document.getElementById(id).getElementsByTagName("input");
    for(var x=0; x < inputs.length; x++) {
        if (inputs[x].type == 'checkbox'){
            inputs[x].checked = !inputs[x].checked;
        }
    }
}
 
</script>
 
<div id="parent_box">
 
    <input type="checkbox" name="foo" value="1" /> 1<br/>
    <input type="checkbox" name="foo" value="2" checked="checked" /> 2<br/>
    <input type="checkbox" name="foo" value="3" checked="checked" /> 3<br/>
 
    <br/>
    <input type="button" value="Toggle checkboxes" 
        onclick="toggle_checkboxes('parent_box')" />
 
</div>

Initial URL

                                

Initial Description

                                

Initial Title
Toggle checkboxes

Initial Tags

                                

Initial Language
HTML