Jump to content

Recommended Posts

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!!  ???

Link to comment
https://forums.phpfreaks.com/topic/148911-calling-javascript-within-php/
Share on other sites

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']
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.