Jump to content

check all checkboxes


hassank1

Recommended Posts

here is a start for you

 

<script>
function setCheckBox(){
if(document.getElementById('main_checkbox').checked){
	document.getElementById('my_checkbox').setAttribute('checked','checked');
}else{
	document.getElementById('my_checkbox').removeAttribute('checked');
}
}
</script>
subcheckbox 
<input type="checkbox" id="my_checkbox" /><br />
main checkbox 
<input type="checkbox" id="main_checkbox" onChange="setCheckBox()" /><br />

Link to comment
https://forums.phpfreaks.com/topic/105036-check-all-checkboxes/#findComment-538024
Share on other sites

ought to do it

//js
function checkAll()
{
     // get all the inputs
var cb = document.getElementsByTagName('input');

     // loop through them
for(var i=0;i<cb.length;i++)
{
             // looking only for checkboxes
	if(cb[i].type=='checkbox')
                {
                      // check it
		cb[i].checked=true;
                 }
}
}


//html
<input type="checkbox" name="checkAll" onclick="checkAll()" />

Link to comment
https://forums.phpfreaks.com/topic/105036-check-all-checkboxes/#findComment-538027
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.