[prog] JavaScript question: submitting a form to a new Window in IE 5.5

Rachel McConnell rachel at xtreme.com
Fri Oct 7 06:25:45 EST 2005


As something to try if Almut's suggestion doesn't work: play around with 
a return value after the onsubmit="" javascript:

<form action="" target="foo" onsubmit="window.open('', 'foo',
  'width=450,height=300,status=yes'); return false;">

                                      ^^^^^^^^^^^^^

Generally, returning a boolean from an event handler is supposed to 
permit (return true) or suppress (return false) the default behavior of 
the event the handler is attached to.  (Of course, the usual variances 
of behavior apply here, and I haven't tested this on IE 5.5 WinNT as I 
don't have easy access to it.)

Minor mod to Almut's idea - pass in the form and the name of the window 
as parameters to the submit_form() function, making it more flexible & 
reusable:

<html>
<head>
   <script type="text/javascript">
   <!--
   function submit_form(actualForm, windowName) {
     window.open('', windowName, 'width=450,height=300,status=yes')
     actualForm.submit()
   }
   // -->
   </script>
</head>

<body>

<form name="myform" action="" target="foo">
<input name="q">
<button type="button" onclick="submit_form(this, 'foo')">Submit</button>
</form>

</body>
</html>


One more thought, which is a lot stringier.  You could pass in the 
desired window size values as parameters to the new page, along with the 
rest of the form input; use an appropriate target value in the <form> 
attributes.  Then create an onload() function in the new page that 
resizes it according to the passed params.  This does require the page 
to know whether it's intended to go in a small new window or not, but if 
it's a Help page or similar, that might not be a problem.

Rachel

Mary wrote:
> Problem: I have an HTML form I want to submit to a new window. ie, I


More information about the Programming mailing list