如何根据`< option>`改变链接形式的动作? [英] how change the link form action a accordance with the `<option>`?
本文介绍了如何根据`< option>`改变链接形式的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个表单是搜索表单。当我点击<选项>
alfamart或bca时,我希望链接更改。
,请按照< option>
/ en2 / maps(alfamart)或(bca)/ b
但如何?
感谢
=jsdata-hide =false>
< form action =/ en2 / maps。$ id。/><! - 地图所在页面的相对网址 - >距离:< select name =textSearchTermsclass =selectpickerdata-live-search =true> < option value =alfamart> Alfamart< / option> < option value =BCA> BCA< / option> < /选择> < input type =submitvalue =Search>< / form><?php $ id = $ _GET ['textSearchTerms'];?>
$ p $你不需要从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>距离:< select name =textSearchTermsclass =selectpickerdata-live-search =true> < option value =alfamart> Alfamart< / option> < option value =BCA> BCA< / option> < /选择> < input type =submitvalue =Search>< / form>
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'];
?>
解决方案
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>
这篇关于如何根据`< option>`改变链接形式的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文