There's a solution for this, but it would require refreshing the page (which isn't that big a deal).
Pass a variable in the url called checked
if there is no value for checked, then set checked to equal either yes or no (depending if you want them all checked or not by default)
If checked equals yes, check all the boxes
if checked equals no, uncheck all the boxes.
So the code would look something like this
<a name="bottom"></a>
<? if (($_GET['checked'] == 'yes') or (!$_GET['checked'])) { ?>
<INPUT TYPE="button" onClick="parent.location='email.php?checked=no#bottom'" VALUE='Uncheck All'>
<? } elseif ($_GET['checked'] == 'no') { ?>
<INPUT TYPE="button" onClick="parent.location='email.php?checked=yes#bottom'" VALUE='Check All'>
<? } ?>
email.php being the page you are on, although you could use <?= $PHP_SELF ?>
I also added #bottom, which is an html anchor so the person is always at that part of the page after the refresh.
Then, where you dynamically build your checkboxes, you'd use something to this effect...
if (($_GET['checked'] == 'yes') or (!$_GET['checked'])) {
echo "<input type=checkbox name='to_email[]' value=" . $row["id"] . " checked>";
} elseif ($_GET['checked'] == 'no') {
echo "<input type=checkbox name='to_email[]' value=" . $row["id"] . ">";
}
Cgraz