I am still learning javascript and need some help changing form "action" based selected option value. Please see html code below:
<form method="post" title="myForm" id="myForm" name="myForm" action="test_auth.php">
<fieldset>
<legend>Request Details</legend>
<p><label>Brand: </label>
<select id="Brand" name="Brand">
<option value"">Select...</option>
<option value="brand">Brand 1</option>
<option value="brand">Brand 2</option>
<option value="brand">Brand 3</option>
<option value="brand">Brand 4</option>
<option value="brand">Brand 5</option>
</select>
</p>
<br />
<p class="submit"><input class="button" name="Submit" type="submit" value="Submit" onclick="actionDetermine();" /></p>
So basically when option "Brand 1" is selected, I want to change the form "action" to test.php. I have written some javascript, see below, but the forms errors on submitting when "Brand 1" is submitted
function actionDetermine() {
var thisform = document.myForm;
if (thisform.elements["brand"] [1].selectedIndex) {
thisform.action ="test.php";
} else if (thisform.elements["brand"] [2].selectedIndex) {
thisform.action="test_auth.php";
} else if (thisform.elements["brand"] [3].selectedIndex) {
thisform.action="test_auth.php";
} else if (thisform.elements["brand"] [4].selectedIndex) {
thisform.action="test_auth.php";
} else if (thisform.elements["brand"] [5].selectedIndex) {
thisform.action="test_auth.php";
} else if (thisform.elements["brand"] [0].selectedIndex) {
thisform.action="test_auth.php";
}
return true;
};
Obviously there is something wrong with the above, can anyone help me out?
Cheers!