Forum Moderators: open
$js = '<script type="text/javascript">
function chek_all() {
var control = document.getElementById("control_box").checked;
if(control) {';
$js_i = '';
$js_e = '';
for($i = 0; $i < $rows; $i++) {
$username = mysql_result($result, $i, "Username");
$formtable .= "\n" . '<tr>
<td style="text-align: center;" ><input type="checkbox" id="' . $username . '_Check" name="' . $username . '_Check" value="1" /></td>
<td style="text-align: center;">' . ucfirst($username) . '</td>
<td style="text-align: center;"><input type="text" name="' . $username . '_Points" value="' . mysql_result($result, $i, "Points") . '" /></td>
<td style="text-align: center;"><input type="text" name="' . $username . '_PointsSinceLastPayOut" value="' . mysql_result($result, $i, "PointsSinceLastPayOut") . '" /></td>
<td style="text-align: center;"><input type="text" name="' . $username . '_DateofLastRun" value="' . mysql_result($result, $i, "DateofLastRun") . '" /></td>
</tr>';
$js_i .= "\n" . 'document.getElementById("' . $username . '_Check").checked = true;';
$js_e .= "\n" . 'document.getElementById("' . $username . '_Check").checked = false;';
}
$js .= $js_i . "\n" . '} else {' . $js_e . "\n" . '}
</script>';
<input type="checkbox" id="control_box" name="control_box" onclick="chek_all()" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript">
window.onload=function() {
if (document.getElementById('onoff')) {
document.getElementById('onoff').onclick=function() { toggleChecks(this.form,this); };
}
}
//
function toggleChecks(form,onoff) {
var all_id = onoff.id;
var sw = (onoff.checked==true)?true:false;
for (j=0;j<form.elements.length;j++) {
var obj = form.elements[j];
if ((obj.type=='checkbox') && (obj.id != all_id)) {
obj.checked = sw;
}
}
}
</script>
</head>
<body>
<form action="" method="post">
<p><input type="checkbox" name="onoff" id="onoff" value="1"> <label for="onoff">All On or Off</label></p>
<p><input type="checkbox" name="chk1" id="chk1" value="1"> <label for="chk1">One</label></p>
<p><input type="checkbox" name="chk2" id="chk2" value="2"> <label for="chk2">Two</label></p>
<p><input type="checkbox" name="chk3" id="chk3" value="3"> <label for="chk3">Three</label></p>
<p><input type="checkbox" name="chk4" id="chk4" value="4"> <label for="chk4">Four</label></p>
<p><input type="checkbox" name="chk5" id="chk5" value="5"> <label for="chk5">Five</label></p>
</body>
</html>
function toggleChecks(form,onoff) {
var ignore = new Array('chk2','chk4');
var all_id = onoff.id;
var sw = (onoff.checked==true)?true:false;
for (j=0;j<form.elements.length;j++) {
var ignoreThis=false;
var obj = form.elements[j];
for (k=0;k<ignore.length;k++) {
if (obj.id==ignore[k]) { ignoreThis=true; break; }
}
if ((obj.type=='checkbox') && (obj.id != all_id) && ignoreThis==false)) {
obj.checked = sw;
}
}
}