...

View Full Version : checking a checkbox from a group using javascript



bomma_murali
12-09-2004, 12:54 PM
hi all,
I have a group of checkboxes assigned with a same name dynamically. like this i have different groups. Also i have a checkbox for each group. if click on this checkbox all the checkboxes in this group are to be checked. how can i do this.
i would apprieciate if any one provide me a solution for this.
thanks
Murali

jbot
12-09-2004, 03:33 PM
loop through them, and, if each invidual array item (ie checkbox) is not checked, then check it.

Brandoe85
12-10-2004, 01:27 AM
this should help you out...


<html>
<head>
<script language="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>

DHTML Kitchen
12-10-2004, 01:49 AM
You can shorten that and make it faster with a local variable.


for(var i = 0, form= document.forms[0]; i < form.check.length; i++) {
form.check[i].checked = form.check1.checked;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum