Nate_23 Posted November 30, 2011 Share Posted November 30, 2011 Hey, I'm trying to make a single checkbox that will select all the checkboxes in a group. I have a working code; at least it works on the first two sets of checkboxes. However, it does not work on the final set. (Quick note: the mysql stuff all works. It can easily be tested by changing the MySQL table name.) If anyone has found a way around this problem that would be great. Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript"> function checkAll(checkName, checkValue) { for (i = 0; i < checkName.length; i++) checkName.checked = checkValue.checked? true:false } </script> <?php echo "<form name='first'> <input type='checkbox' name='checkThem' onClick='checkAll(document.second.checkGroup,this)'>Check All (1)</form> <form name='second'> <input type='checkbox' name='checkGroup' >First<br/> <input type='checkbox' name='checkGroup' >Second<br/> <input type='checkbox' name='checkGroup' >Third<br/> <input type='checkbox' name='checkGroup' >Fourth</form>"; echo "<br/>"; ?> <form name="third"> <input type="checkbox" name="checkThem" onClick="checkAll(document.fourth.checkGroup,this)">Check All (2)</form> <form name="fourth"> <input type="checkbox" name="checkGroup" >First<br/> <input type="checkbox" name="checkGroup" >Second<br/> <input type="checkbox" name="checkGroup" >Third<br/> <input type="checkbox" name="checkGroup" >Fourth </form> <?php echo "<br/>"; include_once "connect_to_mysql.php"; $sql = "SELECT * FROM mysqltablename"; $result = mysql_query($sql) or die ("Couldn't get results."); $num = mysql_num_rows($result); echo "<form name='fifth'> <input type='checkbox' name='checkThem' onClick='checkAll(document.sixth.checkGroup,this)'>Check All (3)</form>"; while($row = mysql_fetch_assoc($result)) { $id = $row['id']; echo "<form name='sixth'> <input type='checkbox' name='checkGroup'>$id<br/></form>"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/252105-select-all-checkboxes/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.