Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2004, 09:50 PM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Opening a separate window from a Form

To the Great Thinkers in JS land:

Does anybody know how to open a separate (and controlled, regarding attributes) window from a form? While I've done this hundreds of times from a basic href link (using the various arguments to the "window.open" method), I've never learned how to do it from within the form tag, nor the input tag (as part of a form). I also know how to manipulate the pop-up window features once it's open, but I'd rather set the control before it opens.

Here's my basic HTML code:
-------
<form name="layoutRegion1Form" action="http://edev:8765/custom/query.html" target="_blank" method="get">
<input type="hidden" name="col" value = "enet">
<input type="hidden" name="style" value = "standard">
<table class="popSearchTable" height="84" border="0" cellspacing="0"
cellpadding="0" style="background-image: url(../img/cell_bg.gif)">
  <tr align="left" valign="top">
    <td width="740" height="50">
      <div style="position:absolute;left:18px;top:12px"><p class="body11Gray">Search E-Net as per your <br>text search criteria</p></div>
      <div style="position:absolute;left:192px;top:18px"><inp ut type="reset" name="SEARCH-97" value="Clear" id="FormsButton1" class="button11"></div>
      <div style="position:absolute;left:18px;top:46px"><inpu t id="FormsEditField1" type="text" name="qt" size="19" maxlength="50" class="form13"></div>
      <div style="position:absolute;left:192px;top:45px"><inp ut type="submit" name="SEARCH-97" value=" Go " id="FormsButton2" class="button13"></div>
    </td>
  </tr>
</table>
</form>
-------

Of course, the "target" attribute (above) will open a separate window, but without the needed control. That's not good enough.

Any help would be greatly appreciated.

 
Old April 6th, 2004, 02:04 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The bad news is, you can't.

The target attribute will result in the browser determining the new window size, properties and location. In most cases, that will mean a non-maximized window with the dimensions of the last window you had when you closed your browser the last time you used it.

I am not even sure if you can do it with JavaScript. You can fire a custom function instead of input type="submit" and then set the action attribute of the form, but I am not sure if you can change the target window as well, and still specify all the details.

However, since you are using a GET form, you could set the options for a new window in the custom function, collect all the form values yourself, construct a href out of these values and open the new window with the appropriate href.

Am I making sense to you?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 7th, 2004, 09:32 AM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, Imar, this does make sense, in fact, this was my intention.

It's just that, I'm not sure how to reconcile the "action" property of the form, and the "value" property of the text input.

Regardless, I will proceed and try and write the function through trial and error, unless someone out there can provide me with code which they've already written. I've hunted around in my various JS books, as well as on the web, but so far haven't found what I need.

Thanks.

- Bradley

 
Old April 7th, 2004, 09:37 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Here's more suggestions:

1)

Make a DIV dynamically appear when the form submits, and since the DIV is not actually a new window, you can pass values straight to it using JavaScript.

2)

Pass the form values to the server, and then any page can request them (requires PHP or ASP or something).

HTH,

----------
---Snib---
----------

<><
 
Old April 7th, 2004, 09:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, since I don't know your form, I can't write the entire function for you (besides that would spoil all the fun, don't you think?), but I can give you some ideas.

If you go for the QueryString solution, there is no need to change the action property. Try something like this:
Code:
<script type="text/javascript">
function OnSubmit()
{
  var LastName = document.layoutRegion1Form.LastName.value;
  var FirstName = document.layoutRegion1Form.FirstName.value;
  var newURL = '/NewPage.asp?LastName=' + LastName + '&FirstName=' + FirstName;
}
</script>
At this point, newURL contains a URL like:

/NewPage.asp?LastName=Spaanjaars&FirstName=Imar

This url can now safely be passed to a standard window.open function that determines the properties of the window.

HtH,

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 8th, 2004, 06:19 PM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:
This is very helpful. I know how to proceed, now. Thanks.

Snib:
A DIV is too limiting. I'm displaying potentially extensive search results.

 
Old April 9th, 2004, 01:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Be aware that there is a limit on length of the QueryString that you can send. It depends on the browser, but usually you should keep it under 1024 characters.

So, this solution works well for small forms with text boxes, but you may run into problems when you offer your users a text area.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Eurochild by Massive Attack (Track 7 from the album: Protection)






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access form controls from separate class? paket C# 6 August 1st, 2007 06:18 AM
opening Web form in another window? Thagi ASP.NET 1.x and 2.0 Application Design 2 March 31st, 2006 05:40 AM
Using Datagrid...getting data on separate form Renu Classic ASP Databases 4 August 7th, 2004 09:52 PM
Opening New Window p_nut33 Classic ASP Basics 1 August 6th, 2004 08:11 PM
Close Parent window on opening child window pkdev Javascript How-To 8 April 11th, 2004 12:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.