如何根据“<选项>”更改链接表单操作


how change the link form action a accordance with the `<option>`?

此表单是搜索表单。 当我单击"阿尔法玛特"或"BCA"<option>时,我希望更改链接。像这样,链接:/en2/maps(alfamart)or(bca)/ 根据<option>
但是怎么做呢?

谢谢

<form action="/en2/maps".$id."/"><!--Relative url to the page that your map is on-->
    Distination: 
    <select name="textSearchTerms" class="selectpicker" data-live-search="true">
        <option value="alfamart">Alfamart</option>
	    <option value="BCA">BCA</option>
    </select> 
    <input type="submit" value="Search">
</form>
<?php
$id = $_GET['textSearchTerms'];
?>

您不需要从 URL 获取值,您可以通过选择框值来更改表单操作。

$('.selectpicker').change(function(){
if($(this).val() == 'alfamart'){
	$('form').attr('action','alfamart.html');
  alert('action is alfamart.html');
} else {
	$('form').attr('action','BCA.html');
  alert('action is BCA.html');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="/en2/maps">
    Distination: 
    <select name="textSearchTerms" class="selectpicker" data-live-search="true">
        <option value="alfamart">Alfamart</option>
	      <option value="BCA">BCA</option>
    </select> 
    <input type="submit" value="Search">
</form>