Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  105] [ 6]  / answers: 1 / hits: 62096  / 13 Years ago, fri, april 29, 2011, 12:00:00

I have a delete button that is tied to some comments on a page i have. When you click the delete button i am trying to get a confirm dialog box to pop up asking if you are sure you want to delete the comment. Clicking OK should run the function to delete the comment and clicking cancel should not run the function but simply close the dialog box.



This is my code:



onclick=confirm('Are you sure that you want to delete this comment?'); commentDelete(1);


My problem: When i click cancel the delete function still runs. My guess is that the function is still getting called because when i click cancel it just is stepping forward in the JavaScript and calling the function. How can i accomplish this correctly? I know this is probably a simple problem. Thanks for any help!


More From » confirm

 Answers
109
onclick=if (confirm('Are you...?')) commentDelete(1); return false


You are missing an if. In your version, first you get a question, and then regardless of the answer, you call commentDelete.


[#92479] Thursday, April 28, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
benitoh

Total Points: 150
Total Questions: 113
Total Answers: 104

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
benitoh questions
Sun, Mar 21, 21, 00:00, 3 Years ago
Mon, May 13, 19, 00:00, 5 Years ago
;