tags:

views:

62

answers:

3

When a user clicks a submit button I want the form to be submitted. However, just before this happens, I want a window to pop open and for them to fill in some data. Once they do this and they close that child window, I want the POST request to be made.

Is this possible, if so how? I just need help after the window closes, how can I make that POST request continue?

Thanks all

+1  A: 

Couldn't you just add a

onunload=parent.form.submit()?

http://www.w3schools.com/jsref/jsref_onunload.asp

Byron Whitlock
I just found out about that beautiful function. Thank you for your reply. [SOLVED]
Abs
But then the form is always submitted, even if the user doesn't fill it out, just by trying to leave the page.
Ian Elliott
not if you hook the onload handler before when you call window.close();
Byron Whitlock
+1  A: 

You can do something like this.. (note the code is simplified and you can probably structure it better)

This is in your main document with the form:

var childFilled = false;
myForm.onsubmit = function() {
    if(!childFilled) {
        window.open(...);
        return false;
    }
};

function submitFormFromChild() { 
    childFilled = true;
    myForm.submit();
}

And in the window's code you have something like this:

window.onunload = parent.submitFormFromChild;

Untested, unproven, but the general concept is something like this =)

Jani Hartikainen
A: 

To be clear: you meant to ask (and asked in the question) how to intercept form-submission in the browser.

The title of your post implies that you are asking how to perform an asynchronous HTTP POST operation, do something else, and subsequently wait for that HTTP POST operation to complete. That whole process is not necessarily related to user interaction and is not necessarily related to HTML form submission, and it is not the same thing at all as what you meant to ask (and asked in the question).

Justice