选择选项时设置 $_GET 值

set a $_GET value when option is selected

当一个选项被选中时,我如何通过 $_GET 设置 filter_branch=true 和 filter_branch_val=sony?

<select name="filter_brand">
   <option>Sony</option>
   <option>LG</option>
</select>

所以我有类似 http://mypage.com/index.php?filter_branch=true&filter_branch_val=sony 的东西用于 sql 查询过滤器。

您可以为此使用 jQuery。我已经测试过了,它正在工作。

添加这个:

<head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> </head>

HTML

<select id="myselect" name="filter_brand" onchange="javascript:goToURL()">
   <option>No selection *</option>
   <option>Sony</option>
   <option>LG</option>
</select>

脚本

<script>
function goToURL(url){
var option = $( "#myselect option:selected" ).text();
var yoururl = "http://www.example.com/";
var url = yoururl+ "?page="+ option;
window.location.replace(url);
}
</script>

试试这个,然后回来找我。 我使用 This and This 作为参考。

如果 java 脚本功能适合您。请试试这个代码

HTML

<select name="filter_brand" onchange="sendFilter(this.value)">
 <option>Sony</option>
 <option>Lg</option>
 <option>Samsung</option>
</select>

Javascript

<script type="text/javascript">
 function sendFilter(vaa)
 {
     console.log(vaa);
     window.location.href = 'product.php?  
     filter_branch_val='+vaa+'&filter_branch=true';
 }
</script>