wobuck Posted January 8, 2011 Share Posted January 8, 2011 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>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/223757-checkuncheck-checkboxhelp/ Share on other sites More sharing options...
dragon_sa Posted January 8, 2011 Share Posted January 8, 2011 Hi thats a javascript function on the page see this example http://www.somacon.com/p117.php should help Quote Link to comment https://forums.phpfreaks.com/topic/223757-checkuncheck-checkboxhelp/#findComment-1156601 Share on other sites More sharing options...
wobuck Posted January 8, 2011 Author Share Posted January 8, 2011 Yes, I have found this type of solution but I am unable to put it in the php code without getting errors - my coding knowledge of mixing javascript and php is limited. Can you help? Quote Link to comment https://forums.phpfreaks.com/topic/223757-checkuncheck-checkboxhelp/#findComment-1156604 Share on other sites More sharing options...
dragon_sa Posted January 8, 2011 Share Posted January 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/223757-checkuncheck-checkboxhelp/#findComment-1156614 Share on other sites More sharing options...
wobuck Posted January 8, 2011 Author Share Posted January 8, 2011 Many Thanks Starting to code now and will post when successful! Quote Link to comment https://forums.phpfreaks.com/topic/223757-checkuncheck-checkboxhelp/#findComment-1156617 Share on other sites More sharing options...
wobuck Posted January 8, 2011 Author Share Posted January 8, 2011 Great stuff! All now working many thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/223757-checkuncheck-checkboxhelp/#findComment-1156623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.