rrayner Posted September 5, 2012 Share Posted September 5, 2012 Hi All I have got a javascrit script which should on a button press check all or uncheck all checkbox's it works on the web site I got it from but when I have placed it into my php page I cant get it to work. I have tried the javascript in a none php page and it works. Below is my php page. Can some one point in the right direction please. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <?php //******************************************************* // // Open Connection to Database // //******************************************************* include ("connection.php"); //$row_ID = (isset($_GET['row_ID'])) ? $_GET['row_ID'] : ''; $row_ID = (isset($_POST['row_ID'])) ? $_POST['row_ID'] : ''; //if(isset($_POST['row_ID']) && $_POST['row_ID']) $row_ID = $_POST['row_ID']; if(isset($_POST['COMPANY_id']) && $_POST['COMPANY_id']) $COMPANY_id1 = $_POST['COMPANY_id']; //$row_ID = "RMAD100"; $SHIPDATE = date("Y-m-d"); ?> <head> <link rel="stylesheet" type="text/css" href="robtest1.css" /> </head> <body> <SCRIPT LANGUAGE="JavaScript"> <!-- // by Nannette Thacker // http://www.shiningstar.net // This script checks and unchecks boxes on a form // Checks and unchecks unlimited number in the group... // Pass the Checkbox group name... // call buttons as so: // <input type=button name="CheckAll" value="Check All" //onClick="checkAll(document.myform.list)"> // <input type=button name="UnCheckAll" value="Uncheck All" //onClick="uncheckAll(document.myform.list)"> // --> <!-- Begin function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } // End --> </script> <div id="wrapper"> <fieldset> <legend>JOB ID Update</legend> <?php include 'menus.php'; ?> <br> <br> <br> <form name="myform" action="jobid.php" method="POST"> <?php echo "<input type=\"hidden\" name=\"row_ID\" value=\"$row_ID\"><br>"; echo"<div class=\"mytext2\">Advice Note No.</div><input type=\"text\" id=\"ADVICENOTE\" name=\"ADVICENOTE\" value=\"\" title=\"ADVICENOTE\"><br> <div class=\"mytext2\">Job ID</div><input type=\"text\" id=\"JOBID2\" name=\"JOBID2\" value=\"\" title=\"JOBID2\"><br> <div class=\"mytext2\"><b>Shipped Date</b></div> <input type=\"text\" id=\"SHIPDATE\" name=\"SHIPDATE\" value=\"$SHIPDATE\" title=\"SHIPDATE\" maxlength=\"10\" size=\"10\"><br>"; echo "<div class=\"mytext2\"><b>Customer</b></div> <select name=\"COMPANY_id\"> <option>$COMPANY_id</option>"; $query1 = "SELECT DISTINCT COMPANY_id FROM addresses ORDER BY COMPANY_id ASC"; $result1 = mysql_query($query1); $num_rows=mysql_num_rows($result1); while ($row=mysql_fetch_array($result1)) { $COMPANY_id = $row["COMPANY_id"]; echo "<option value=\"$COMPANY_id\">$COMPANY_id</option>"; } echo "<option></option></select><br>"; echo "<table width=\"50%\"><tr>"; echo "<td align=\"center\" Class=\"TableRowTitle\" width=\"12.5%\">Serial No</td><td align=\"center\" Class=\"TableRowTitle\" width=\"12.5%\">Select</td></tr>"; $query1 = "SELECT * FROM products where jobid = '$row_ID' order by SERIALNO asc LIMIT 0 , 1000;"; $result1 = mysql_query($query1); $num_rows=mysql_num_rows($result1); while ($row=mysql_fetch_array($result1)) { $SERIALNO = $row['SERIALNO']; echo "<tr onMouseOver=\"this.bgColor = '#C0C0C0'\" onMouseOut =\"this.bgColor = '#EDEDED'\" bgcolor=\"#EDEDED\"> <td Class=TableRow8 width=\"12.5%\">$SERIALNO</td><td Class=TableRow8><input type=\"checkbox\" name=\"id[]\" value=\"$SERIALNO\"></td></tr>"; } echo "</table>"; $ADVICENOTE =$_POST['ADVICENOTE']; $SHIPDATE =$_POST['SHIPDATE']; $JOBID2 =$_POST['JOBID2']; //$COMPANY_ID =$_POST['COMPANY_ID']; if (!empty($_POST['id'])) { //echo "ROW_id = $row_ID<br>"; $query =("UPDATE products SET ADVICENOTE = '$ADVICENOTE' , SHIPDATE = '$SHIPDATE' , COMPANY_ID = '$COMPANY_id1' , JOBID = '$JOBID2' WHERE SERIALNO IN('" . implode("','",$_POST['id']) . "')"); //AND SERIALNO IN('" . implode("','",$_POST['id']) . "')"); //echo "$query<br>"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); } ?> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> <input type="submit" name="submit1" value="SAVE" Class="LoginButtons"> </form> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/268012-got-a-javascript-script-for-checking-a-check-box-which-i-cant-get-to-work/ Share on other sites More sharing options...
Adam Posted September 5, 2012 Share Posted September 5, 2012 You're passing document.myform.list into the functions, but a quick search found no check inputs named "list". Quote Link to comment https://forums.phpfreaks.com/topic/268012-got-a-javascript-script-for-checking-a-check-box-which-i-cant-get-to-work/#findComment-1375405 Share on other sites More sharing options...
rrayner Posted September 5, 2012 Author Share Posted September 5, 2012 Thank you Took out the .list from the end of document.myform.list and it all worked. Thank you again. Quote Link to comment https://forums.phpfreaks.com/topic/268012-got-a-javascript-script-for-checking-a-check-box-which-i-cant-get-to-work/#findComment-1375426 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.