aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Submit form and close window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Submit form and close window" Watch "Submit form and close window" New topic
Author

Submit form and close window

Veni Velkoor
Ranch Hand

Joined: Oct 17, 2001
Posts: 65
Hello, Not sure if I posted this before but I still have this issue--
Is there a way to submit a form and close the browser window with the click of a single button. On one of my pages, I have an F3 button and when clicked, I would like to submit a form which transmits an '3' value to my backend CICS system(in order to logoff from CICS) and also simultaneously close my browser window on the frontend . Attached below is the code I am trying to run--
function functionkey(k){
if (k == 3)
{
document.Form1.c__Aid_I.value=k;
document.Form1.submit();
window.close();
}
else {
document.Form1.c__Aid_I.value=k;
document.Form1.submit();
}
}
What is happening is the window closes, but the form is not getting submitted prior to the window.close().
Any ideas/suggestions will be appreciated!
Thanks much..........
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You can't (safely) close the browser window before the response arrives, cos that's not how HTTP works.
The easiest way to do it is to have the use click the button, send the request, process the request, and send a response (all business as usual). The only difference is that the page you return closes the window
ie it looks like this:

The standard way is to just send a page saying "you have now logged off". Oterwise you can't be sure that the user doesn't have other browser windows open and whether these windows are viewing your site or some other site...
Dave.
Reda Mokrane
Ranch Hand

Joined: Jul 25, 2001
Posts: 237
Veni,
Try this:
Veni Velkoor
Ranch Hand

Joined: Oct 17, 2001
Posts: 65
David, your reply seems logical, but it leads to another question. When I submit my form, the servlet sends back another page and this page needs to be closed ONLY IF the user had clicked on the F3 button on the previous screen...for any other button it is business as usual...so, what do you think the best way is to pass the F3 to the next screen...hidden fields or session variables.....?
Thanks ,
Veni
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The F3 button (as you call it) can change the 'action' property of the form before submitting it. That way it can be detected and handled cleanly and separately to the other options. Then the page that F3 submits to can handle the situation separate to the existing functionality.
Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Submit form and close window