iseriouslyneedhelp Posted July 9, 2012 Share Posted July 9, 2012 I have a form on my page with results and check boxes for each row and a delete button at the bottom. The form onSubmit calls a javascript funtion that confirms the user wants to delete. If okay, they they are pushed to my delete page and everything works fine. So, here's the issue, everything works perfectly if I do not put "return false;" in the javascript. With "return false;" in my javascript, the user is just taken to the delete page and nothing happens, it's blank. No errors, nothing. Also, no records are deleted and they are not forwarded to my header location. Without "return false;" in my js, no matter if "ok" or "cancel" is clicked, the record is deleted. Is there something wrong with my code, am I missing something obvious here? INDEX.PHP (ONLY GIVING YOU FORM SECTION) <form method="post" action="" onSubmit="return removemult();" name="updateleads" id="updateleads"> <table> <tbody> while ($stmt->fetch()) { echo'<tr> <td><input type="checkbox" name="checked[]" value="'.$ID.'"></td> <td><a href="/cms/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td> </tr>'; </tbody> </table> <input name="remove" type="submit" value="Delete"> </form> JS function removemult() { if (confirm("Are you sure you want to delete these leads?")) { window.location = '/cms/scripts/delete-mult.php'; } return false; // If removed, no matter if ok or cancel is clicked, the rows are deleted. Leave it in and cancel works, // but if ok is clicked, it goes to /cms/scripts/delete-mult.php but it's just a blank white page, no errors, nothing. } DELETE-MULT.PHP <?php require("/config.php"); // DELETE MULTIPLE ROWS if(isset($_POST['remove']) && (isset($_POST['checked']))) { $checked = $_POST['checked']; $count = count($_POST['checked']); var_dump($checked); for($i=0;$i<$count;$i++) { $del_id = $checked[$i]; $stmt = $mysqli->query("DELETE FROM contacts WHERE ID = '$del_id'"); } if($stmt) { header('Location: ' . $_SERVER['HTTP_REFERER']); } else { echo "Error: (" .$mysqli->connect_errno . ")" . " " . $mysqli->connect_error; } } $mysqli->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265447-when-return-false-is-added-script-doesnt-execute/ Share on other sites More sharing options...
jcbones Posted July 9, 2012 Share Posted July 9, 2012 Try: <form method="post" action="/cms/scripts/delete-mult.php" onSubmit="return removemult();" name="updateleads" id="updateleads"> <table> <tbody> while ($stmt->fetch()) { echo'<tr> <td><input type="checkbox" name="checked[]" value="'.$ID.'"></td> <td><a href="/cms/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td> </tr>'; </tbody> </table> <input name="remove" type="submit" value="Delete"> </form> function removemult() { if (confirm("Are you sure you want to delete these leads?")) { return true; } return false; // If removed, no matter if ok or cancel is clicked, the rows are deleted. Leave it in and cancel works, // but if ok is clicked, it goes to /cms/scripts/delete-mult.php but it's just a blank white page, no errors, nothing. } Quote Link to comment https://forums.phpfreaks.com/topic/265447-when-return-false-is-added-script-doesnt-execute/#findComment-1360385 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 9, 2012 Author Share Posted July 9, 2012 That did it...was trying to stay away from using return true; Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/265447-when-return-false-is-added-script-doesnt-execute/#findComment-1360390 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.