Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit form to popup window?

Tags:

javascript

I have a script that submits a form to a popup window but instead of displaying the form's action (process.php), it displays nothing (blank window). Heres my script:

function redirectOutput() {
var myForm = document.getElementById('formID');
var w = window.open('about:blank','Popup_Window','toolbar=0,scrollbars=0,location=0,statusb
ar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');
myForm.target = 'Popup_Window';
return true;
}
like image 933
Jonah Katz Avatar asked Sep 08 '11 20:09

Jonah Katz


2 Answers

It works, but you have a newline suddenly in your window.open.

This works just fine for me: http://jsfiddle.net/pimvdb/N3YSG/.

var myForm = document.getElementById('formID');
myForm.onsubmit = function() {
    var w = window.open('about:blank','Popup_Window','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');
    this.target = 'Popup_Window';
};
like image 90
pimvdb Avatar answered Oct 08 '22 23:10

pimvdb


An easy way to submit form in popup window:

HTML:

<form action="..." method="post" onsubmit="target_popup(this)">
    <!-- form fields etc here -->
</form>

Javascript:

function target_popup(form) {
    window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
    form.target = 'formpopup';
}

Source: http://www.electrictoolbox.com/post-form-popup-window-javascript-jquery/

like image 39
ramiz Avatar answered Oct 08 '22 22:10

ramiz