/    Sign up×
Community /Pin to ProfileBookmark

"Check All" Checkboxes

I have developed a password protected form to provide checkbox selection of email addresses for communication inside a club. The checkbox inputs (awkwardly, I suspect) come from a mySQL table. The form works manually, sending emails, as planned, but I am attempting to add a “standard” CHECKALL function to make selection of all members easier, but do not understand how to make these checkboxes recognized by the function.

The new script is highlighted in [COLOR=DarkRed]red[/COLOR].

Thanks, –Larry

<html><!– #BeginTemplate “/templates/main.dwt” –><!– DW6 –>
<head>

[COLOR=DarkRed]<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>
[/COLOR]
<!– #BeginEditable “doctitle” –>
<title>MBC</title>
<!– #EndEditable –>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>

<body bgcolor=”#FFFFFF” text=”#000000″>

<table width=”700″>
<tr>
<td width=”170″ height=”123″ align=”center”><a href=”index.html”><img src=”-logo.gif” width=”120″ height=”123″ border=”0″></a></td>
<td width=”2″>&nbsp;</td>
<td width=”6″>&nbsp;</td>
<td width=”2″>&nbsp;</td>
<td> <h1>MBC<br>
</h1></td>
</tr>
<tr>
<td width=”170″ valign=”top”>&nbsp;</td>
<td width=”2″ valign=”top”>
<p>&nbsp;</p></td>
<td width=”6″ valign=”top”>&nbsp;</td>
<td width=”2″ height=”8″ valign=”top”>&nbsp;</td>
<td width=”599″ valign=”top”>&nbsp;</td>
</tr>
<tr>
<td width=”170″ align=”center” valign=”top”>
<p><a href=”../index.html”>Home</a></p>
<table width=”100%” border=”0″>
</tr>

</table>
<p><br>
<br>
<br>
<br>
<br>
<br>
<br>
</p>
<p>&nbsp;</p></td>
<td width=”2″ valign=”top”>&nbsp;</td>
<td width=”6″ valign=”top” bgcolor=”#669900″>&nbsp;</td>
<td width=”2″ valign=”top”>&nbsp;</td>
<td valign=”top”><!– #BeginEditable “Body2” –>
<head>

<meta HTTP-EQUIV=”Pragma” content=”no-cache”>
<META HTTP-EQUIV=”Expires” CONTENT=”Mon, 04 Dec 1999 21:29:02 GMT”>
<meta http-equiv=”Content-Language” content=”en-us”>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>

</head>

<form method=”POST” action=”sender.php”>

<title>New Page 1</title>
<td> <h1 align=”left”> Contact Form </h1>

<body>

<div><b><bold>
<label for=”name”>Your Name (sender): </label></b></bold><br>
<input type=”text” name=”name” id=”name” size=”35″>
</div>

<div>
<br><b><bold>
<label for=”subject”>Subject: </label></b></bold><br>
<input type=”text” name=”subject” id=”subject” size =”39″>
</div>

<br>
<b>
Select Addressees: <p>

</b>
</div>

[COLOR=DarkRed]<form name=myform action=”” method=post>[/COLOR]<table>
<tr><td>
<?
include(“dbinfo.inc.php”);
mysql_connect(‘localhost’,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);
$query=”SELECT * FROM rosterlist”;
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
unset($email1); unset ($name);
$i=0; //30
while ($i < $num) {
$name=mysql_result($result,$i,”name”);
$memberno=mysql_result($result,$i,”memberno”);
$address1=mysql_result($result,$i,”address1″);
$address2=mysql_result($result,$i,”address2″);
$address3=mysql_result($result,$i,”address3″);
$phone=mysql_result($result,$i,”phone”);
$email1=mysql_result($result,$i,”email1″); [COLOR=DarkOrange]// database entries are read[/COLOR]
$email2=mysql_result($result,$i,”email2″);
$car1=mysql_result($result,$i,”car1″); //40
$car2=mysql_result($result,$i,”car2″);
$car3=mysql_result($result,$i,”car3″);
$car4=mysql_result($result,$i,”car4″);
$car5=mysql_result($result,$i,”car5″);

if ($email1 <>””) {
$emails = array($email1); [COLOR=DarkOrange]// checks to insure there is an email address[/COLOR]
echo “<form action=”{$_SERVER[‘PHP_SELF’]}” method=”post”>n”;

foreach($emails as $email)
{

echo “<input type=”checkbox” value=”{$email}” name=”emails[]”>{$name}</input><br /> n”; [COLOR=DarkOrange]//displays checkboxes w/ names[/COLOR]}}
++$i; [COLOR=DarkOrange]// the email address (not name) is sent to the mailer[/COLOR]}
?>
[COLOR=DarkRed]<br>

<input type=button value=”Check All” onClick=”this.value=check(this.form.”emails[]”)”> [/COLOR] </td></tr>
</table>
</form>
</center>

<bold><b><p>
<label for=”message”>Message: </bold></b></label><br>
<textarea rows=”15″ name=”message” cols=”55″ id=”message”></textarea><br>

</div>

<input type=”submit” value=”SEND MESSAGE” name=”submit””<br>

</form>

</body>

</html>
[COLOR=DarkRed]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@emoritzAug 13.2006 — onclick="check(document.forms['myform'].elements['emails[]'])"

this.form."emails[]" implies that the input button has a child Node named "form"

while you're at it, clean up that code. you got stuff everywhere that shouldnt be (two head tags?). also, use css for positioning (no tables!).
×

Success!

Help @LarryS spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...