Home > database >  How to close browser after form has been submitted?
How to close browser after form has been submitted?

Time:12-03

I am trying to submit a form and then the browser has to close. But I cannot understand why it will not work. For some reason, it will close the window, but it does not submit the form.

$('.cancel-confirm').on('click', function () {
    $(this).closest('form').submit();
    alert('Submitted - your window will now close');
    window.close();
});
<form asp-action="CancelActivity" method="post"  style="right:5em; top:20%;">
    <input type="hidden" name="ActivityID" value="@item.Activityid" />
    <input type="hidden" name="status" value="@(item.IsCancelled == true ? "false" : "true")" />
    <button  type="submit"> @(item.IsCancelled == true ? "Genaktiver" : "Deaktiver") </button>
</form>

Tried to submit the form with jQuery and then close the window

CodePudding user response:

try to put an ID in your form,

$('#form-id').submit(function () {
    window.close();
});

CodePudding user response:

I see you are using jQuery, you can use ajax

$('.cancel-confirm').on('click', function () {
    $.post( "yourprocessor.php", { name: "Your Name", sex: "Male" })
      .done(function( data ) {
        alert('Submitted - your window will now close');
        window.close();
      });    
});

then process your submitted form.

  • Related