File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Popups, actions and javascript OH MY! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Popups, actions and javascript OH MY!" Watch "Popups, actions and javascript OH MY!" New topic

Popups, actions and javascript OH MY!

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
I'm looking to have a popup window do a submit and then close the window. Can I do this with one javascript action? Has anyone had to do this? Its basically a database update from a popup. The expected result is that when this button is hit, the update will happen and then the window will close.

Your thoughts...

By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
on the body onload you need to do onload="document.formName.submit()"

use the action to take the form submission to another page. on that page do onload="window.close()"

If you do not want to take it to another page, than you just need to have the server side code write out the close statement to the page.

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
OR you can look into Ajax and avoid the whole pop up situation.
Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
I have done this.

Option 1: Submit the page in the popup. The return page will have either an error message and a close button, or if it successfully submetted, a javascript that will reload the parent and close itself:

Option 2: Have the javascript call a function on the opener.

You might need to hide a form in the opener page. You can also pass attributes with the function call. Then the function sets the values in the opener page and then submits the hidden form.

Option one is what I ended up using. It is cleaner. But it is all up to you on your process flow.

The squeaky wheel gets the grease. Well, that or replaced...
I agree. Here's the link:
subject: Popups, actions and javascript OH MY!
Similar Threads
Close the IE window through javascript
disable CLOSE (X) button on a popup window
Closing a parent window from a popup
PopUP window on another window close
popup window