2

How would I set filter_branch=true and filter_branch_val=sony via $_GET when an option is selected?

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

So I have something like http://mypage.com/index.php?filter_branch=true&filter_branch_val=sony to be used for sql query filter.

  • When u want to send the values as query string on change event of select box? – Azeez Kallayi Mar 26 '15 at 10:36
  • @fireflieslive I've posted a working code, you also need to add a new option called something like "no selection *". Otherwise you can't select the default option. Please accept answer if you are satisfied :) – Gjert Mar 26 '15 at 11:20

2 Answers2

0

You can use jQuery for this. I have tested it and it is working.

Add this:

<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

<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>

Try this and come back to me. I used This and This as reference.

Community
  • 1
  • 1
Gjert
  • 1,069
  • 1
  • 18
  • 48
0

If java script function will work for you . please try this code

HTML

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

Javscript

<script type="text/javascript">
 function sendFilter(vaa)
 {
     console.log(vaa);
     window.location.href = 'product.php?  
     filter_branch_val='+vaa+'&filter_branch=true';
 }
</script>
Azeez Kallayi
  • 2,567
  • 1
  • 15
  • 19
  • Have you added: ` ` in your ? – Gjert Mar 26 '15 at 10:57
  • @GjertGjersund , no because here i am using just java script not jquery – Azeez Kallayi Mar 26 '15 at 10:59
  • Also `+vaa+` gets me an error in my IDE, not sure why though. Of course. Should have seen that. However, the post I commented is working atleast :) – Gjert Mar 26 '15 at 10:59
  • If you want to see it in work go here: www.gogetit.no. I added the code to my website. – Gjert Mar 26 '15 at 11:09
  • i just uplaoded the script which i posted here . http://azeezkallayi.com/demo/test/select.html its working fine here – Azeez Kallayi Mar 26 '15 at 11:14
  • I've come across the same problem as you, we can't select the item previously selected. Which means you need to have an option such as No selection made or something similar. – Gjert Mar 26 '15 at 11:18