Change form action to select options
I want to change the action of the form based on the selection value.
Hi guys,
<form name="store" id="store" method="post" action="">
<select name="storeID">
<option value="/stores/store6.php">6</option>
<option value="/stores/store10.php">10</option>
</select>
</form>
Now I need a form action to use the value of the select option. For example:
If option 1 is selected, use the following form action / stores / store6.php
+3
source to share
4 answers
<form name="store" id="store" method="post" action="" id="FORM_ID" >
<select name="storeID">
<option value="/stores/store6.php">6</option>
<option value="/stores/store10.php">10</option>
</select>
</form>
<script type="text/javascript">
document.getElementById('storeID').onchange = function(){
document.getElementById('FORM_ID').action = '/'+this.value;
}
</script>
check it out, I want it to work.
+2
source to share
Add to function onchange
<select name="storeID" onchange='changeAction(this.value)'>
and add to javascript
function changeAction(val){
document.getElementById('storeID').setAttribute('action', val);
}
This will change the action after the selected option is changed to the selected parameter value.
0
source to share