Hello all, im trying to create a function that will allow me to auto check checkboxes from another checkbox.
Here is my code:
I cant get it to work at the moment, however, i think im very close. Any ideas?
Here is my code:
Code:
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Untitled Page</title>
<SCRIPT LANGUAGE="JavaScript">
function check(field,x) {
for (i = 0; i < field.length; i++) {
var id = field[i].id;
if (field[i].checked == true)
{
if (x = "All")
{
field[i].checked = true;
}
else
{
if(id.indexOf(x+'-') != -1){
field[i].checked = true;
}
}
}
else
{
if (x = "All")
{
field[i].checked = false;
}
else
{
if(id.indexOf(x+'-') != -1){
field[i].checked = false;
}
}
}
}
}
</script>
</head>
<body>
<form name=myform action="" method=post runat=server>
<table>
<tr><td>
<b>Checkbox Example</b><br>
<input type=checkbox name=list id="1-1" value="1A">A<br>
<input type=checkbox name=list id="1-2" value="2A">A<br>
<input type=checkbox name=list id="2-1" value="3A">A<br>
<input type=checkbox name=list id="2-2" value="4">B<br>
<input type=checkbox name=list id="2-3" value="5">B<br>
<br>
<input type=checkbox id="Checkbox" onClick="this.value=check(this.form.list,1)">Check All A<br>
<input type=checkbox id="Checkbox1" onClick="this.value=check(this.form.list,2)">Check All B<br>
<input type=checkbox id="Checkbox2" onClick="this.value=check(this.form.list,All)">Check All B<br>
</td></tr>
</table>
</form>
</body>
</html>
I cant get it to work at the moment, however, i think im very close. Any ideas?