Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

brain teaser. submit a form to a new window of a specific dimension

Status
Not open for further replies.

toolkit

Programmer
Aug 5, 2001
771
GB
One for you javascript experts.
I have a highly complex form. When the user clicks the submit button, I would like a new window to be opened with a specific width and height. In order to achieve this, I have been hand constructing my query string, appending to my URL, and then using window.open. That is:
Code:
  // create a query string
  var query = "?";
  var separator = "&";
  var inputs = document.getElementsByTagName('INPUT');
  for(var i = 0; i < inputs.length; i++) {
    if(i > 0) query += separator;
    query += inputs[i].name + &quot;=&quot; + escape(inputs[i].value);
  }
  inputs = document.getElementsByTagName('input');
  for(var i = 0; i < inputs.length; i++) {
    if(i > 0) query += separator;
    query += inputs[i].name + &quot;=&quot; + escape(inputs[i].value);
  }

  // assume only one selection allowed
  // this code will need to be modified if selects
  // are designed to allow multiple selections
  var selects = document.getElementsByTagName('SELECT');
  for(var i = 0; i < selects.length; i++) {
    if(i > 0) query += separator;
    var select = selects[i];
    var option = select.options[select.selectedIndex];
    query += select.name + &quot;=&quot; + escape(option.value);
  }
  selects = document.getElementsByTagName('select');
  for(var i = 0; i < selects.length; i++) {
    if(i > 0) query += separator;
    var select = selects[i];
    var option = select.options[select.selectedIndex];
    query += select.name + &quot;=&quot; + escape(option.value);
  }

  // open window
  var width = (screen.width / 3) * 2;
  var height = (screen.height / 3) * 2;
  var left = (screen.width - width) / 2;
  var top = (screen.height - height) / 2;
  var features = &quot;menubar=yes,left=&quot;+left+&quot;,top=&quot;+top+&quot;,width=&quot;+width+&quot;,height=&quot;+height;
  window.open(&quot;ReportRequest&quot;+query, null, features);
Very nasty, and very prone to error. Is there no way of using myform.sumbit() to the same effect. I had tried using submit and immediately resizing the new window, but this looked nasty as well :-( Ideas anyone?
Thanks, Neil
 
Here you go!

<script>
function subForm(){
window.open(&quot;&quot;, &quot;reportWin&quot;, &quot;menubar=yes,left=100,top=100,width=100,height=100&quot;)
document.myForm.action = &quot; document.myForm.target = &quot;reportWin&quot;
document.myForm.submit()
}
</script>
Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
Nice one. Couldn't see the wood for the trees :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top