Why does the below still delete even if I hit cancel on the alert popup? What am I missing?
onClick="confirm(\'Are you sure you want to delete '.esc_attr($this->event_name).'?\')"
Syntax. window. confirm("sometext"); The window.
window. confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.
You can create a JavaScript confirmation box that offers yes and no options by using the confirm() method. The confirm() method will display a dialog box with a custom message that you can specify as its argument.
Alert box is used if we want the information comes through to the user. Confirm box is used if we want the user to verify or accept something.
If you return false
from your onclick
handler it will cancel the default action of the click. So try this:
onClick="return confirm(\'Are you sure you want to delete '.esc_attr($this->event_name).'?\')"
That will return whatever value the confirm()
returns, i.e., true
if you click OK and false
otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With