hinchcliffe Posted October 24, 2007 Share Posted October 24, 2007 Hi, there I have a script that I need to change up a bit. So what I want it to do is select all boxes at once when the select button is clicked. I have a code that will do that but I now need to change my name from name="list" to name="list[]" and it's messing up the rest of the script. Can some one tell me the right code so I can use name="list[]"? Thanks. Site: www.bbold.com/strataman/mail.php Here is my code... <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> <?php // Connect to DataBase include 'includes/dbconnect.php'; // Query database $query = "SELECT * FROM mail"; $rs = mysql_query($query); echo 'Subscription List <br /><br />'; echo "<form name=\"myform\" action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">" . "<br />"; while($row = mysql_fetch_array($rs)) { echo "<input type=\"checkbox\" name=\"list[]\" value=\"" .$row['email']. "\" >" . " <a href=\"mailto:" . $row['email'] . "\">" . $row['email'] . "</a><br />"; } // If summit button clicked do this!! if($_POST['submit']) { foreach($_POST['list'] AS $email){ echo $email . "; " ; } } ?> <br /> <input type=button value="Check All" onClick="this.value=check(this.form.list)"> Thanks Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 25, 2007 Share Posted October 25, 2007 I wrote a quick lil function in firebug that does it function checkBoxes(){ var cb = document.getElementsByTagName('input'); for(i in cb){ if(cb[i].type == 'checkbox') cb[i].checked = true; } } checkBoxes(); Quote Link to comment Share on other sites More sharing options...
hinchcliffe Posted October 25, 2007 Author Share Posted October 25, 2007 Sorry, I'm very bad with javascript, How would I implement that with my code? Thanks for helping - Justin. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 25, 2007 Share Posted October 25, 2007 change <input type=button value="Check All" onClick="this.value=check(this.form.list)"> to <input type=button value="Check All" onClick="checkBoxes();"> Quote Link to comment Share on other sites More sharing options...
hinchcliffe Posted October 25, 2007 Author Share Posted October 25, 2007 thanks so much Quote Link to comment 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.