-Strider-
May 16 2005, 07:26 AM
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
May 16 2005, 07:34 AM
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.
-Strider-
May 16 2005, 07:39 AM
ok cool thanks, got any links to tutorials on how to do this?
Stephen
May 16 2005, 07:59 AM
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
May 16 2005, 08:12 AM
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.
-Strider-
May 16 2005, 09:00 AM
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
May 16 2005, 09:01 AM
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.