JavaScript confirm cancel button not stopping JavaScript -


i have delete button tied comments on page have. when click delete button trying confirm dialog box pop asking if sure want delete comment. clicking ok should run function delete comment , clicking cancel should not run function close dialog box.

this code:

onclick="confirm('are sure want delete comment?'); commentdelete(1);" 

my problem: when click cancel delete function still runs. guess function still getting called because when click cancel stepping forward in javascript , calling function. how can accomplish correctly? know simple problem. help!

onclick="if (confirm('are you...?')) commentdelete(1); return false" 

you missing if. in version, first question, , regardless of answer, call commentdelete.


Comments