Form submit or cancel submit after confirm dialog

javascript, jquery, submit

Solution

You can call `event.preventDefault()` when you do not want form to get submitted.

$("#button").click(function(event){
    if(!confirm ("your message"))
       event.preventDefault();
});

event.preventDefault()

Description: If this method is called, the default action of the event will not be triggered.

Problem

It is posible cancel form submit if i click Cancel? ``` $("#button").click(function(){ confirm ("Are you ready?"); $("#form")[0].submit(); }); ``` Now any (after OK and Cancel) time form are submited. I try this logicly should work. ``` $("#button").click(function(){ confirm ($("#form")[0].submit();); }); ```

Original source