I have a basic javascript confirm dialog to confirm whether or not a user wants to proceed with an action. The dialog works correctly if the user simply clicks OK or Cancel. However, if the user clicks Cancel, then re-triggers the dialog, then clicks OK the form is not submitted.
I’ve included my code below, is there a better way to handle this when what I’m doing here?
$("#myButton").click(function (event) {
var result = confirm("Are you sure?");
if (result) {
return true;
} else {
return false;
}
});
Note that I’ve also tried event.preventDefault in place of return false and I see the same result.
Now I might get what you’re trying to achieve.
Just bind the event to your form submit handler instead of the button click. This will also trigger, if the user is sending the form using his keyboard etc.
http://jsfiddle.net/2tSbJ/