Help - Search - Members - Calendar
Full Version: Confirm Prompt
Invision Power Services > Community Forums > Community Web Design and Coding
-Strider-
in PHP, how would i use a prompt window to confirm whether the user really wants to perform an action?

eg a user clicks on a delete button, then a popup window says 'are you sure you wish to delete this topic. if they click yes then it deletes, if they click no then it does nothing
Phil Mossop
You would have to do this user JavaScript, it's impossible in PHP because it's server side. If the user presses 'Yes' the JavaScript would redirect to the new page, or if they press 'No' then do nothing. original.gif
-Strider-
ok cool thanks, got any links to tutorials on how to do this?
Stephen
CODE
function confirmDelete(id) {
    if (confirm("Are you sure you wish to delete this?")) {
        window.location.href = "script.php?action=delete&id=" + id);
    }
}


Something like that is the most basic example
Phil Mossop
If you want that to appear when someone clicks a link you would do:

HTML
<a href="javascript:confirmDelete(x)">Click Me!</a>


Where X is the ID of the item. original.gif
-Strider-
not sure what im doing wrong, but it isnt working for me.

Stephen - i presume i am putting that in the head tags, in between a <script type="text/javascript"> </script> tag?

EDIT: nevermind, steve you left out a bracket before "script.php...
Stephen
actually I didn't, I put one at the end thats the one which isn't need :-"
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.