View Single Post
Old 02-19-2007, 06:44 AM   #7 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,713
redhead is on a distinguished road
Here is a small test which shows it:
Code:
<html>
<head>
<script language="javascript">
function checkAll(table){
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e=document.forms[0].elements[i];
		if ((e.name.substring(0,table.length) == table) &&
			(e.name.indexOf('allbox') < 0) && (e.type=='checkbox'))
		{
			e.checked=eval("document.forms[0]."+table+"_allbox.checked");
		}
	}
}
</script>
</head>

<body>
<form>
<table border="1">
<tr>
<td>
<input type="checkbox" value="on" name="table1_allbox" onclick="checkAll('table1');"/> Check 

all<br />

<h3>Fruit</h3>
<input type="checkbox" value="on" name="table1_apples" /> Apples<br/>
<input type="checkbox" value="on" name="table1_oranges" /> Oranges<br/>
<input type="checkbox" value="on" name="table1_bananas" /> Bananas<br/>
</td>
</tr>
<tr>
<td>
<input type="checkbox" value="on" name="table2_allbox" onclick="checkAll('table2');"/> Check 

all<br />

<h3>Fruit</h3>
<input type="checkbox" value="on" name="table2_apples" /> Apples<br/>
<input type="checkbox" value="on" name="table2_oranges" /> Oranges<br/>
<input type="checkbox" value="on" name="table2_bananas" /> Bananas<br/>
</td>
</tr>
</table>
</form>
</body>
</html>
as you can see, I had to make a small change to the lookout for the "allbox" check, since at this point there are several allboxes...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote