Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form submit or cancel submit after confirm dialog

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(););
});
like image 785
Klapsius Avatar asked Jan 11 '23 06:01

Klapsius


1 Answers

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.

like image 79
Adil Avatar answered Jan 18 '23 23:01

Adil