mattstuehler
mattstuehler

Reputation: 9322

How to submit a form on a child HTML window, then call a Javascript function on the parent window, then close the child window

All,

This should be a pretty simple question, but I haven't found quite the answer I'm looking for yet.

I have a parent HTML window. When a user clicks a button on that window, it opens a child window (e.g., "childA.asp")

That child window includes a form. Here's what I'd like to happen when the user submits that form:

  1. The data in the form is saved
  2. The child window closes
  3. The parent window updates to reflect the new data

How can I implement this?

Should the form on childA.asp post the data to another page (e.g., "childB.asp"), which saves the data, then calls a JavaScript function on the parent window notifying it to update, then close itself?

If so, how would you do this?

Many thanks in advance.

Upvotes: 3

Views: 2034

Answers (1)

Pointy
Pointy

Reputation: 413866

Javascript code in your child page can refer to the parent page via window.opener. Thus what could happen is this:

  1. Child page submits the form to the server
  2. Server does stuff and responds with a "result" page
  3. The "result" page is either the original form with errors, or else a little page with just a <script> block to do:

    window.opener.timeToReloadYourself();
    window.close();
    

Upvotes: 3

Related Questions