OnClick Javascript Confirmation Window

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.


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!!!


You need to return the value from that 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"