user782104 user782104 - 4 months ago 10
HTML Question

How to interrupt the form posting , until pressing the confirm button?

There is a form like this:

<form action="" method="post">
<input type="submit" value="Delete Me">
</form>


I would like to change it to , when pressing the submit button, open a warning modal, If press the 'confirm' at the modal, then the form process.

Some attempt code but I wonder are there any way to 'continue' the form process after interrupt it, thanks a lot.

$(function () {
$('.delete_form').on("submit",function(){
$('#deleteModal').modal('toggle');
return false; //pause the submit
});

$('.confirm_del').on("click",function(){
return true; //process the form submit
});
});

Answer

Use the following code. Button is changed into a normal button from submit button..

<form action="" method="post" id="f1">
   <input type="button" id="b1" value="Delete Me">
</form>

<script>
  $('#b1').click(function(){
        $('#deleteModal').modal('toggle');
  });

  $('.confirm_del').on("click",function(){
         $("#f1").submit(); //process the form submit
  });
</script>