title: Redirecting to a new URL using javascript
body: <p>I am trying to redirect my page to a different url depending on what the user selects from the drop down list. If the user selects "A", the url is the default URL that's in the action attribute of the form but if the user selects "B", I want to redirect it to a different url. </p>
  
  <p>My problem has been no matter what I do, it always redirects to the default URL(ie oldUrl.do) even if I select "B" from the drop down. </p>
  
  <p>What can I do to point it to the newUrl.do?</p>
  
  <p>Note: I am using Struts 1.2 and testing it on IE8. </p>
  
  <p><strong>My jsp page:</strong></p>
  
  <pre><code>&lt;form name="myForm" method="post" action="oldUrl.do" id="myForm"&gt;
  
      &lt;select name="modeOfT" id="choice"&gt;&lt;option value="A"&gt;A&lt;/option&gt;
          &lt;option value="A"&gt;A&lt;/option&gt;
          &lt;option value="B"&gt;B&lt;/option&gt;
      &lt;/select&gt; 
  
      &lt;input type="submit" name="submitBtn" onclick="submitForm()"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Javascript function:</strong></p>
  
  <pre><code>function submitForm(){
      var form = document.getElementById("myForm");
      var mode = document.getElementById("choice");
      if(mode.value == "B"){
          $(form).attr("action", "newUrl.do");
      }
  } 
  </code></pre>
  
  <p>Following are other things I have tried and they still take me to "oldUrl.do": </p>
  
  <ol>
  <li><p>document.location.href("newUrl.do");</p></li>
  <li><p>window.location.href="newUrl.do";</p></li>
  <li><p>top.location.href="newUrl.do";</p></li>
  <li><p>parent.location.href="newUrl.do";</p></li>
  <li><p>window.location.replace("newUrl.do");</p></li>
  <li><p>window.location="newUrl.do";</p></li>
  </ol>