Page 1 of 1

onClick Confirm and Execute PHP Code

Posted: Thu May 28, 2009 1:01 am
by jkwok
Hi,

I have a tool bar consisting of links. One link in particular is to delete a database item. Is there a way to have a confirmation window pop up when the user clicks on the delete link, and if they confirm deletion then the necessary PHP code can be called on to perform the work?

This link exists on a page that displays the database item. So if they click delete, they must confirm. When confirmed, the deletion is performed and the page is redirected.

Here is what the link looks like currently:

Code: Select all

<a href="" onClick="confirmation(<?php echo $_GET['id']; ?>); return false;">Delete</a>
Here is the confirmation() function:

Code: Select all

 
<script type="text/javascript">
<!--
  function confirmation(ID)
  {
    var answer = confirm("Are you sure you want to delete this article?")
    if (answer)
    {
      window.location = "news.php";
    }
  }
//-->
</script>
 
Currently, all this done is simply redirect when confirmed because I'm doubtful on how PHP can be embedded into javascript like this, so I didn't bother including any PHP code. If this isn't possible, I'm open to suggestions!

Any help would be greatly appreciated!

Re: onClick Confirm and Execute PHP Code

Posted: Thu May 28, 2009 12:11 pm
by kaszu

Re: onClick Confirm and Execute PHP Code

Posted: Fri Jun 26, 2009 3:25 pm
by Attilitus
Here are some demos that will help. http://demos.mootools.net/

Look at HTTP Request and Form.send you should be able to implement what you want with some very minor editing of those demos. (Although investing a little time in becoming comfortable with mootools would be well worth the effort.)