onClick Confirm and Execute PHP Code
Posted: Thu May 28, 2009 1:01 am
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:
Here is the confirmation() function:
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!
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>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>
Any help would be greatly appreciated!