PDA

View Full Version : Submitting a Form to a Popup Window


Rex
05-25-2004, 09:55 PM
Hello everybody -

Here is a short and sweet code snippet for submitting a form to a popup window. It only requires modifying the <form> tag a bit. Non-JavaScript users simply get a regular new window.
<form action="formParser.php" method="POST" target="newFormWindow" onsubmit="window.open('about:blank', 'newFormWindow', 'width=340,height=260');">

.....

</form>

- Rex

glenngv
05-26-2004, 07:54 AM
You can simplify it a bit by using this.target

<form target="newFormWindow" onsubmit="window.open('about:blank', this.target, 'width=340,height=260')">

Rex
05-26-2004, 04:08 PM
Hello Glenngv -

Thanks! :) Didn't think of that

- Rex

Alex Vincent
05-26-2004, 06:52 PM
I'm not sure that will work properly in later browsers such as Mozilla. (I'm not sure it won't either, but...) Mozilla uses an event listeners model; the this object may refer to the window, not the form element.

Rex
05-26-2004, 07:37 PM
Hello Alex Vincent -

That is interesting information. I assume that we should make the code:
<form action="formParser.php" method="POST" target="newFormWindow" onsubmit="window.open('about:blank', (event.srcElement? event.srcElement.target : event.target.target), 'width=340,height=260');">

.....

</form>
then :)

- Rex

glenngv
05-27-2004, 03:57 AM
I'm not sure that will work properly in later browsers such as Mozilla. (I'm not sure it won't either, but...) Mozilla uses an event listeners model; the this object may refer to the window, not the form element.
I think you're wrong Alex. When the this keyword is used within the event handler in the element, it refers to the element not the window.

The common use of the this keyword in the form element is in the form validation where the form reference is passed to the validation function.

Try this demo page:

<html>
<head>
<script type="text/javascript">

window.name="mywindow";

function validate(f){
alert(f.name);
alert(f.target);
alert(f.mytext.value);
}
</script>
</head>
<body>
<form name="myform" target="mytarget" onsubmit="return validate(this)">
<input type="text" name="mytext" value="blah" onclick="alert(this.name)" />
<input type="submit" />
</form>
</body>
</html>

Alex Vincent
05-27-2004, 08:52 PM
Like I said, I'm not sure. (Unfortunately, the computer I use for development is unable to reach the Internet... again...)

LeXRus
06-14-2004, 07:45 AM
thx rex. and i code a init function to make this html nifty by using <form target="_pop">
http://www.blueidea.com/bbs/newsdetail.asp?id=1585536