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

岁酱吖の 提交于 2019-12-02 04:49:08

问题


This form is search form. when I click the <option> "alfamart" or "bca", I want the link change. like this, link: /en2/maps(alfamart)or(bca)/ in accordance with the <option>
but how?

thanks

<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'];
?>

回答1:


You don't need to get value from URL, you can change form action by select box value.

$('.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>


来源:https://stackoverflow.com/questions/35264051/how-change-the-link-form-action-a-accordance-with-the-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!