From: FAQ server on
-----------------------------------------------------------------------
FAQ Topic - How do I POST a form to a new window?
-----------------------------------------------------------------------

Use the target attribute on the form, opening a window with
that name and your feature string in the onsubmit handler of the
FORM.

<form action="" method="post"
target="wndname" onsubmit="window.open('',this.target);return true;">

http://www.htmlhelp.com/reference/html40/forms/form.html


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

From: nick on
On Jun 28, 7:00 pm, "FAQ server" wrote:
> FAQ Topic - How do I POST a form to a new window?
> Use the target attribute on the form

That should be enough, right?

>, opening a window with
> that name and your feature string in the onsubmit handler of the
> FORM.

Is this necessary? Shouldn't the UA open a new window with that name
if it has not been created yet?

> <form action="" method="post"
> target="wndname" onsubmit="window.open('',this.target);return true;">

Is the 'target' attribute valid html? Why not something like (leaving
it as simple as possible):

<form action="/blah" method="post">
<script>
var form=document.forms[0];
form.target="wndname";
// do we need all this?
form.onsubmit=function(){
window.open('',form.target); // '' or 'about:blank'?
return true;
}
</script>

Here's something I wrote yesterday that's sort of related...
Submitting a form to another (invisible) window so the page doesn't
need to navigate. It's been done a million times of course, but maybe
someone else can use it, or maybe you guys will get a kick out of it
or something...

It silently submits a form in an iframe, calling an optional callback
when the form loads. I think there is an IE frame onload thing i might
need to work around for the callback but can't remember what it is
exactly.

I wonder if it would be better to use the target attribute of the
existing form instead of cloning the form into a new frame... what do
you guys think?

function sendForm (form, cb) {

var f = document.createElement('iframe'),
clone = form.cloneNode(true),
fName = (+((''+Math.random()).substring(2))).toString(36),
hidden = 'width:0px;height:0px;border:none;'
+ 'margin:0px;padding:0px;position:absolute;';

f.setAttribute('name', fName);
f.setAttribute('style', hidden);

document.body.appendChild(f);

var frame = window.frames[fName];

frame.document.body.appendChild(clone);
if (cb) f.onload=function(){ return cb(frame, f); }
frame.document.forms[0].submit();
}