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.
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.
What can I do to point it to the newUrl.do?
Note: I am using Struts 1.2 and testing it on IE8.
My jsp page:
<form name="myForm" method="post" action="oldUrl.do" id="myForm">
<select name="modeOfT" id="choice"><option value="A">A</option>
<option value="A">A</option>
<option value="B">B</option>
</select>
<input type="submit" name="submitBtn" onclick="submitForm()">
</form>
Javascript function:
function submitForm(){
var form = document.getElementById("myForm");
var mode = document.getElementById("choice");
if(mode.value == "B"){
$(form).attr("action", "newUrl.do");
}
}
Following are other things I have tried and they still take me to "oldUrl.do":
document.location.href("newUrl.do");
window.location.href="newUrl.do";
top.location.href="newUrl.do";
parent.location.href="newUrl.do";
window.location.replace("newUrl.do");
window.location="newUrl.do";