Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  97] [ 7]  / answers: 1 / hits: 31255  / 14 Years ago, mon, april 19, 2010, 12:00:00
<p><span class=linky><a href=deletephone.php?id=' . $row['id'] . '>Delete Phone</a></span></p><br />


I have the above code that I am using to link to a delete script.
I want to somehow incorporate Javascript with a simple onclick confirmation. This way if they choose OK, I can run the code to delete the item from the database, but if they choose Cancel then I can cancel the operation and do nothing.



I have tried a whole variety of functions with changing the window.location to the delete file, and trying to cancel the href= if they choose Cancel, but it always goes to the link regardless of what the user clicks.



I would like to be able to keep the delete functions inside the same PHP file if possible, but this is not necessary at all.



Thanks in advance!



ASIDE: If there is a simple PHP way to check IF the alert was confirmed or denied, that could work also. Any way to check what the user chooses and then run my simple delete PHP command.


More From » php

 Answers
73

If you just want a simple confirmation:



<a href=deletephone.php?id=' . $row['id'] . ' onclick=return confirm('Really delete?');>Delete Phone</a>


confirm prompts the user and returns true if they say OK, false if they say Cancel.


[#97038] Thursday, April 15, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carrington

Total Points: 674
Total Questions: 90
Total Answers: 108

Location: Burundi
Member since Sat, Aug 21, 2021
3 Years ago
;