PDA

View Full Version : Submit a form to a new window?


WA
04-30-2003, 09:52 PM
I was emailed this question yesterday, and it got me rather curious. Is there a reliable way to use a new window to process/submit a form once the "submit" button has been clicked? The basic target attribute works, though it obviously doesn't allow one to specify the dimensions/attributes of the new window:

<form action="submit.pl" method="post" target="formwindow">
<input type="text" size="15" value="Testing">
<input type="submit" value="Submit!">

Now, the person who emailed me also included the following script, which he says does work with more refinely tuning the popup window, though it only works when the method="get":

<script>

function submitForm(theform) {
var formwindow= window.open(theform.action, "targetwindow", "width=400,height=400");
}

</script>

<form name="sampleform" action="YOUR-URL" method="GET" target="targetwindow">
contents of your form...
<input type="button" onClick="submitForm(document.forms.sampleform);">
</form>


How is method="post" different as far as JavaScript's ability to process the form in a new window?

Thanks,

liorean
04-30-2003, 10:07 PM
IIRC:
GET uses the url (search part) for sending a form. JavaScript can because of that send the form.
POST on the other hand uses HTTP message body to send the form, and JavaScript has no way to send an HTTP message body. (Well it has, using XMLHTTP/XMLHttpRequest in ie/moz, but that is proprietary, and affected by the JavaScript cross-domain security rules.)
The POST gets sent just the URL, and thus visits the page, but doesn't send the form.

The DOM WG has discussed adding a way to make full HTTP requests instead of just uri requests, but so far nothing of the kind has appeared in the DOM3LS module. It may still be added in DOM4, though, but that feels a bit distant.

beetle
04-30-2003, 11:02 PM
Originally posted by WA
How is method="post" different as far as JavaScript's ability to process the form in a new window?None whatsoever. The method of the form has no impact on what happens to/with the form before submission.

As you can see (http://www.codingforums.com/showthread.php?s=&threadid=18408), targeting a form to a new (popup) window is quite easy.

That will use a javascript popup if scripting is available, and a regular new (named) window if it's not.

C'mon WA, these are your forums -- you should know the search function (http://www.codingforums.com/search.php?s=&action=showresults&searchid=115059&sortby=lastpost&sortorder=descending) better by now :p

WA
05-01-2003, 02:40 AM
Lol thanks Beetle. I'm going to more closely examine your solution, though the script I had posted above does not work with method=post.

BTW, here's a tutorial I just dug up on the subject that seems to involve a lot of unnecessary work one way or the other: http://devhood.com/tutorials/tutorial_details.aspx?tutorial_id=496