Question

I have the following form which creates a list of options to a dropdown field. Upon change of the selected value, the script resubmits the form and opens in a new tab. How can I have the form open in a new window with predefined dimensions (width, height)?

    <form action="STRcontact_us.asp" method="post" name="frmsubmit" target="new"> 

  <select name="options" onChange="javascript: document.forms['frmsubmit'].submit()"> 

<option value="sales">Select Department</option> 
<option value="Material Handling Components">Material Handling Components</option> 
<option value="Construction Components">Construction Components</option> 
<option value="Track Pad ">Track Pad</option> 
</select>
</form> 
Was it helpful?

Solution

Try giving the select an ID and add this to the head

Live Demo

window.onload=function() {
  document.getElementById("sel1").onchange=function() {
    window.open("","newWin","width=400,height=500");
    this.form.submit();
  }
}

using

<form action="STRcontact_us.asp" method="post" name="frmsubmit" target="newWin"> 

  <select name="options" id="sel1"> 

If IE gives you a hard time we need to change the script a bit

window.onload=function() {
  document.getElementById("sel1").onchange=function() {
    window.open("","newWin","width=400,height=500");
    setTimeout(function() {
      document.forms[0].submit();
    },100);// allow IE to get over the shock of opening a window
  }
}

Other thing: no need to have javascript: in an event handler

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top