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" class="absolute ff f-36 foreground-white" 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 class="btn ff f-22 background-transparant foreground-black cancel-confirm" type="submit"> @(item.IsCancelled == true ? "Genaktiver" : "Deaktiver") </button> </form>
Tried to submit the form with jQuery and then close the window
Advertisement
Answer
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.