...

View Full Version : checking multiple checkboxes by clicking on another check box



chelvis
01-26-2005, 08:38 PM
I have 2 set of check boxes. One check box says "Select all" and when the user checks on this check box, it should check a group of check boxes. THe only thing is I wouldnt know how many check boxes to be checked at one time. Can I do this in a loop?

I wrote some thing like below, but as I said if I dont know how many check boxes to be checked, then I cannot write like this since this will write for a definite number of check boxes.

<script language="javascript">
function checkAll4() {
document.info.all3.checked = true; }

function checkOthers4() {
if (document.info.all3.checked == fasle)
{
document.info.agri.checked = true;
document.info.astro.checked = true;
document.info.biosc.checked = true;
document.info.chem.checked = true;
document.info.comp.checked = true;
}
}
</script>

Brandoe85
01-26-2005, 09:36 PM
Heres an example:


<html>
<head>
<script type="text/javascript">
function checkAll()
{
for(var i = 0; i < document.forms[0].check.length; i++)
{
if(document.forms[0].check1.checked)
{
document.forms[0].check[i].checked = true;
}
else
{
document.forms[0].check[i].checked = false;
}
}
}

</script>
<body>
<form>
<input type="checkbox" name="check1" onclick="checkAll();"><br>
<input type="checkbox" name="check"><br>
<input type="checkbox" name="check"><br>
<input type="checkbox" name="check"><br>
<input type="checkbox" name="check"><br>
<input type="checkbox" name="check"><br>
<input type="checkbox" name="check"><br>
<input type="checkbox" name="check"><br>
</form>
</body>
</html>

chelvis
01-26-2005, 09:52 PM
Thanks Brandoe85!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum