How to submit a form into a new window?

Wait! Before you give me the old target=“_blank” line… please read what I’m trying to accomplish.

Basically, I have a form with two submit buttons. One is called “Save”, and the other is “Preview”. I want the “Save” button to submit the form using normal means (replace the current window)… but the “Preview” button must submit the form into a new window.

Can this be done? I started a thread about this in the HTML forum, and some have said it can be done via javascript, so here I am.

Can I pass the form contents (input tags, etc…) to some kind of javascript function and then have the form submit into a new window? Will I still be able to have the “Save” button NOT open a new window?

Here’s the code I have right now. This basically is just two buttons that open the form into the same window. It’s the Save button that I want to open up into a new window only.
:

<form name="form_name" method="post" action="http://www.domain.com/file.php">
  <input type="submit" name="Save" value="Save">
  <input type="submit" name="Preview" value="Preview">
</form>

Thanks!

try this:


<INPUT TYPE="button" NAME="preview" VALUE="preview" ONCLICK="javascript:window.open('previewpage.html');">

I don’t think your example will work. All it does is open a new html page into a new window. What I would like to do is submit the form into a new window ONLY if the Preview button is clicked.

Thanks!

I have similar question. Also I want to know how to setup the new window with some parameter like width and height

Well, assuming you want the new window to simply preview the contents of the form. You can use what weirdbeard posted. All you have to do in previewpage.html is get the form contents of the opener window. Lets say you had a textarea like on this forum.

document.write(window.opener.document.frm.txt.value);

I have similar question. Also I want to know how to setup the new window with some parameter like width and height

<INPUT TYPE=“button” NAME=“preview” VALUE=“preview” ONCLICK=“javascript:window.open(‘previewpage.html’,‘preview’,‘width=300,height=300’);”>

I do have a similiar problem, 1 form, 4 buttons - with a preview button to preview the form entries. The window.opener is handy but I can’t use it because the contents of the textareas are modified by a PHP-Script (regular expressions etc.).
<INPUT TYPE=“image” NAME=“preview” VALUE=“preview” ONCLICK=“javascript:window.open(‘preview.php’,‘preview’,‘width=800,height=700’);”>
does neither open a window nor interpret the PHP Script.
A preview in a new window would be a pretty solution. Does anybody have an idea ?
Thanks.

This is much easier than you guys are trying to make it

<input type=“submit” value=“Preview” onclick=“this.form.target=‘_blank’;return true;”/>

<input type=“submit” value=“Submit” onclick=“this.form.target=‘_self’;return true;”/>

That’s it.

:agree:

You would :stuck_out_tongue:

/runs

beetle,

how do you do this when you want to specifiy width & height.

I just so happen to have written a script that does that.

http://www.javascriptkit.com/script/script2/form2popup.shtml

JSKit picked it up a while ago :wink: