Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Submit form and close window

 
Veni Velkoor
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Veni,
Try this:
 
Veni Velkoor
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic