title: Open a link using onsubmit
body: <p>I have the following mock snippet:</p>
  
  <p><strong>JS :</strong></p>
  
  <pre><code>function generateLink()
  {
    var A = document.getElementById('AAA').value;
    var B = document.getElementById('BBB').value;
  
    if(B == "1" || B == "2")
      link ='http://' + B + '.' + A + '.domain';
    else if(B == "3" || B == "4")
        link ='http://' + B + '.' + A + '.domain/link.jsp';
    else
      link ='/404.html';
  
    return link;
  }
  
  function showLink()
  {
    var link = generateLink();
  
    document.getElementById("link").href = link;
    document.getElementById("link").innerHTML = link;
  }
  
  document.formName.onsubmit = function(){
      this.action = generateLink();
  }
  </code></pre>
  
  <p><strong>HTML :</strong></p>
  
  <pre><code>&lt;form name="formName" target="_blank"&gt;
  
  &lt;div style="margin: 0 auto; width:600px;"&gt;
  
    &lt;div style="float:left;"&gt;&lt;span&gt;Pick AAA&lt;/span&gt;&lt;br&gt;
      &lt;select id="AAA" onchange="showLink()"&gt;
        &lt;option value="11"&gt;Eleven&lt;/option&gt;
        &lt;option value="12"&gt;Twelve&lt;/option&gt;
        &lt;option value="13"&gt;Thirteen&lt;/option&gt;
        &lt;option value="14"&gt;Fourteen&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  
    &lt;div style="float:right;"&gt;&lt;span&gt;Pick BBB&lt;/span&gt;&lt;br&gt;
      &lt;select id="BBB" onchange="showLink()"&gt;
        &lt;option value="1"&gt;One&lt;/option&gt;
        &lt;option value="2"&gt;Two&lt;/option&gt;
        &lt;option value="3"&gt;Three&lt;/option&gt;
        &lt;option value="4"&gt;Four&lt;/option&gt;
      &lt;/select&gt;  
    &lt;/div&gt;
  
    &lt;div style="float:left; margin-left:120px; margin-right: 40px; margin-top:70px;"&gt;
      &lt;a href="generateLink()" id="link"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
      &lt;input type="submit" value="Go to"&gt;&lt;br&gt;&lt;br&gt;
      &lt;input type="reset" value="Reset Selection"&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>When I run this code what happens is that the <code>href</code> opens the correct <code>url</code> in a new tab, while the <code>submit</code> button opens the page I am currrently on in a new tab. I am not sure what I am doing wrong. Doesn't the <code>document.formName.onsubmit</code> suppose to make the <code>submit</code> button work the same as the <code>href</code>?</p>