Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript close a popup on submit

Ok. I've seen this question as been unanswered for over 10 years..

How do you submit and close a popup in one button call.

suggestions run thus.

function saveNClose()
{
  document.form.submit();
  self.close();
}
this doesn't work because the submit has a redirect, and the self.close is never reached.

function closeLaterNSaveNow();
{
  setTimeout("window.close()",5000);
  document.form.submit();
}
same problem..  the close is never called because the script for the page is gone.

function closeNowNSubmit()
{
  self.close(); 
 document.form.submit();
}
the window closes, but nothing gets saved.  server doesn't even get notified of anything..

<input class='btn btn-success' disabled='disabled' id='SubmitFinal' onclick='closeWindow()' type='submit' value='Finish'>
Well then there's no validation of the data.  it submits before the function is called.

Anyone solve this? I found the same solutions dating back to 2002, and some as recent as this month. I shall continue to look, but I'm hoping someone has nailed it and that that someone answers here

like image 214
baash05 Avatar asked Jan 31 '13 01:01

baash05


People also ask

How to close popup after submitting the form in javascript?

close() script. This will close the pop up window.

How do I close a window after submitting?

In the Form Settings->On Submit->Redirect URL set this value : javascript:window. top. close();

How to close popup window after submit in php?

You can use a link: <a href="#" onClick="CloseAndRefresh(); return:false;">Close</a> Or a button: <input type="button" value="close" onClick="CloseAndRefresh();" Or you can make it part of the submit: <input …


1 Answers

A typical solution is to output a JS snippet that will close the window as a resulting page after submit.

<script type="text/javascript">
    window.close();
</script>

Another solution would be to submit form's data via AJAX, and close the window when request has finished. You can use jQuery Form plugin for that:

$("#myForm").ajaxForm(function() { 
    window.close();
})
like image 77
esycat Avatar answered Sep 24 '22 21:09

esycat