rachwilbraham Posted March 11, 2009 Share Posted March 11, 2009 Hello! I am currently writing a page that displays a list of records from a database and gives the option to delete a record. When the delete button is clicked a pop up window (called with Javascript) is opened to confirm the delete. On the confirm button we need to have the record deleted via the mySQL statement, then we need to close the pop up window and refresh the main page so that the site visitor can see that the record has been deleted from the list. Currently I can do either or, but not both!!! The delete query runs fine, but as soon as I add the javascript function to the button the delete query won't run! The javascript I am using is (in the head tags): <script type="text/javascript"> function refreshmain() { window.opener.location.href=window.opener.location.href; // refresh the main page window.opener.focus(); // focus on the main page window.close(); // close the popup page } </script> And on the button: <input type="submit" name="Confirm" id="Confirm" value="Confirm" <?php echo ("onclick=\javascript:refreshmain()"); ?> /> Does anyone know if I can add a bit of code into the php on the button to say run the delete query first, then call the javascript function?? Thanks!! ??? Quote Link to comment https://forums.phpfreaks.com/topic/148911-calling-javascript-within-php/ Share on other sites More sharing options...
JonnoTheDev Posted March 11, 2009 Share Posted March 11, 2009 What a long winded method. Why not use javascripts own confirmation alert and then if a user clicks ok delete the record on the same page i.e. Heres your javascript function function decision(message, url){ if(confirm(message)) location.href = url; } Heres the link to delete a record. When a user clicks ok at the prompt it will run index.php?action=delete&id=117 (117 is the database id) <a href='#' onclick="decision('Are you sure you want to delete?','index.php?action=delete&id=117')">delete</a> On your index.php or whatever the file is put the code to delete a record: if($_GET['action'] == 'delete') { // code to delete - database id in $_GET['id'] } Quote Link to comment https://forums.phpfreaks.com/topic/148911-calling-javascript-within-php/#findComment-782018 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.