Jump to content

Recommended Posts

I have tried various different methods to put a single field in to enable check/uncheck all items but cannot get any to work. It would be really helpful if someone can supply the correct coding?

 

In anticipation

Thanks

:-[

 

My code:

 

<?php

 

$rowa=0;

 

print("<br></br>");

 

mysql_connect($host,$username,$password); //(host, username, password)

mysql_select_db($database) or die("Unable to select database"); //select which database we're using

$query = "SELECT id, forename, surname, emailaddress FROM master ORDER by surname,forename";

$result = mysql_query($query);

while($row = mysql_fetch_row($result))

{

    $id=$row[0];

    $forename=$row[1];

    $surname=$row[2];

    $email=$row[3];

 

$member="$forename $surname";

 

 

print("<table style=\"BORDER-COLLAPSE: collapse\"  border=\"1\">");

print("<tr><form id=\"checkboxform\" action=\"email.php\" method=\"GET\">");

print("<td width=\"20px\" bgColor=\"#eaf1f7\"><input type=\"checkbox\" name=\"checkbox[$rowa]\" value=\"$id\" checked=\"checked

 

\"></td>");

print("<input type=\"hidden\" style=\"width: 60px\" name=\"id[$rowa]\" value=\"$id\"></td>");

print("<input type=\"hidden\" style=\"width: 60px\" name=\"forename[$rowa]\" value=\"$forename\"></td>");

print("<input type=\"hidden\" style=\"width: 60px\" name=\"surname[$rowa]\" value=\"$surname\">");

print("<input type=\"hidden\" style=\"width: 250px\" name=\"email[$rowa]\" value=\"$email\">");

print("<input type=\"hidden\" style=\"width: 80px\" name=\"active[$rowa]\" value=\"$active\">");

print("<td width=\"135px\" bgColor=\"#eaf1f7\"><font face=\"Arial\" size=\"2\"><div ALIGN=\"LEFT\">$member</div></td>");

print("<td width=\"250px\" bgColor=\"#eaf1f7\"><font face=\"Arial\" size=\"2\"><div ALIGN=\"LEFT\">$email</div></td>");

print("</table>");

$rowa++;

}

print("<td><br></td></tr>");

 

print("<tr><td width=\"105px\" bgColor=\"#eaf1f7\"><font size=\"2\" title=\"$editdeletetxt\"> <input value=\"Send Email\" type=

 

\"Submit\"> To All Ticked Above</td><br>");

print("<br></tr>");

 

?>

Link to comment
https://forums.phpfreaks.com/topic/223757-checkuncheck-checkboxhelp/
Share on other sites

put this above your code in the head section

 

<script language="javaScript" type="text/javascript">
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
if(!document.forms[FormName])
	return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
	return;
var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
	objCheckBoxes.checked = CheckValue;
else
	// set the check value for all check boxes
	for(var i = 0; i < countCheckBoxes; i++)
		objCheckBoxes[i].checked = CheckValue;
}
</script>

THEN NAME YOUR FORM -  the example name here is myForm

then modify the check boxes names

 

then change the name of the check boxes to myCheckbox[your original name here] and give them an id like myCheckbox1, myCheckbox2 etc

 

than add the 2 change buttons

 

eg

 

<input type="button" onclick="SetAllCheckBoxes('myForm', 'myCheckbox', true);" value="Check All">
  
<input type="button" onclick="SetAllCheckBoxes('myForm', 'myCheckbox', false);" value="UnCheck ALL">

 

should work then

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.