hedbanger
07-10-2002, 01:08 AM
i got this code from this board here a while back and have been attempting to adapt it to my needs.
it's for an intranet and only needs to work on i.e.
selecting from a list of groups will create a list of subgroups which can be further refined by checking their boxes. there will be a checkboxes and a button for each of the dynamically created lists.
the first problem is that after the first button is clicked, the next one has to be clicked twice. once to focus it and once to click it. this is very annoying. how do i correct this?
here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>check it out</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- // Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
// End -->
</script>
</head>
<body>
<FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<!-- -->
<br>
<table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center">SET 1</td>
</tr>
<tr>
<td align="center">
<input name="button1"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff" onClick="this.value=check(this.form.elements['SRP2'])" value="Check All">
<br>
<br>
<br>
<br>
<br>
</td>
</tr>
<tr>
<td align="left">
<input type="checkbox" name="SRP2" value="1">
A<br>
<input type="checkbox" name="SRP2" value="2">
B<br>
<input type="checkbox" name="SRP2" value="3">
C<br>
</td>
</tr>
</table>
<p> </p>
<p><br>
</p>
</form>
<FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center">SET 2</td>
</tr>
<tr>
<td align="center">
<input name="button2"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff" onClick="this.value=check(this.form.elements['SRP2[]2'])" value="Check All">
<br>
<br>
<br>
<br>
<br>
</td>
</tr>
<tr>
<td align="left">
<input type="checkbox" name="SRP2[]2" value="1">
Ξ <br>
<input type="checkbox" name="SRP2[]2" value="2">
Ζ<br>
<input type="checkbox" name="SRP2[]2" value="3">
Ω<br>
</tr>
</table>
</form>
</body>
</html>
it's for an intranet and only needs to work on i.e.
selecting from a list of groups will create a list of subgroups which can be further refined by checking their boxes. there will be a checkboxes and a button for each of the dynamically created lists.
the first problem is that after the first button is clicked, the next one has to be clicked twice. once to focus it and once to click it. this is very annoying. how do i correct this?
here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>check it out</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- // Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
// End -->
</script>
</head>
<body>
<FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<!-- -->
<br>
<table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center">SET 1</td>
</tr>
<tr>
<td align="center">
<input name="button1"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff" onClick="this.value=check(this.form.elements['SRP2'])" value="Check All">
<br>
<br>
<br>
<br>
<br>
</td>
</tr>
<tr>
<td align="left">
<input type="checkbox" name="SRP2" value="1">
A<br>
<input type="checkbox" name="SRP2" value="2">
B<br>
<input type="checkbox" name="SRP2" value="3">
C<br>
</td>
</tr>
</table>
<p> </p>
<p><br>
</p>
</form>
<FORM ACTION="" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<table width="150" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center">SET 2</td>
</tr>
<tr>
<td align="center">
<input name="button2"type="button" style="COLOR: #24559E; BACKGROUND-COLOR: #ffffff" onClick="this.value=check(this.form.elements['SRP2[]2'])" value="Check All">
<br>
<br>
<br>
<br>
<br>
</td>
</tr>
<tr>
<td align="left">
<input type="checkbox" name="SRP2[]2" value="1">
Ξ <br>
<input type="checkbox" name="SRP2[]2" value="2">
Ζ<br>
<input type="checkbox" name="SRP2[]2" value="3">
Ω<br>
</tr>
</table>
</form>
</body>
</html>