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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.