How to submit form to new window?

I've marked this as duplicate because I thought your problem was about how to send a form to a popup window. Here is how to do it without using the onsubmit event:

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", xxx);

function submitToPopup(f) {
    var w = window.open('', 'form-target', 'width=600, height=400, any-other-option, ...');
    f.target = 'form-target';
    f.submit();
};

document.body.appendChild(form);

submitToPopup(form);

So instead of using the onsubmit event to create the popup from there, you create it first, just before sending the form, and then send the form to it.


You could do this instead [link],

  1. open a new window
  2. insert form in it
  3. make it submit
  4. which will navigate to url

    var form = document.createElement("form");
    
    form.setAttribute("method", "post");
    form.setAttribute("action", "http://www.yahoo.com");
    
    
    function popitup() {
        newwindow = window.open('', 'name', 'width=800,height=600');
        if (window.focus) {
            newwindow.focus()
        }
        newwindow.document.body.appendChild(form);
        newwindow.document.forms[0].submit();
        return false;
    }
    
    popitup();