OnClick Javascript confirmation window

Why does the following still delete, even if I hit undo in the warning popup? What am I missing?

onClick="confirm(\'Are you sure you want to delete '.esc_attr($this->event_name).'?\')" 
+7
source share
5 answers

If you return false from your onclick handler, it will undo the default action of the click. So try the following:

 onClick="return confirm(\'Are you sure you want to delete '.esc_attr($this->event_name).'?\')" 

This will return any value returned by confirm() , i.e. true if you click OK and false otherwise.

+22
source

Check below ..

 <html> <script language="javascript"> function checkMe() { if (confirm("Are you sure")) { alert("Clicked Ok"); return true; } else { alert("Clicked Cancel"); return false; } } </script> <body> <form name="myForm"> <input type=submit value="Press Me" onClick="return checkMe()"> </form> </body> </html> 

Write what you want to do in Click Ok .

Good luck !!!

+4
source

You need to return the value from this confirm :

 onClick="return confirm(\'Are you sure you want to delete '.esc_attr($this->event_name).'?\')" 

So, if you click cancel, it will be equal to onClick="return false"

+3
source

You may need to use return false; when the user clicks the cancel button in your Javascript code. Otherwise, the script will not cancel the rest of the process.

0
source

You need to return the value from this confirmation:

 onClick="return confirm('Are you sure you want to delete?')" 
0
source

All Articles