-1

So I have this script

search.value = document.getElementById('OptionA').value + " " + document.getElementById('OptionB').value;

that helps me to do a search on wordpress and changes the search url into something like this: mysite.com/?s=OptionA+OptionB, but I need to have something like this:

mysite.com/?s=OptionA+OptionB&post_type=product.

I've tried to change the script into this:

search.value = document.getElementById('OptionA').value + " " + document.getElementById('OptionB').value + "&post_type=product";

but the url comes out like this:

mysite.com/?s=OptionA+OptionB%26post_type%3Dproduct. What do I have to do?

This is the product-searchform.php code:

<script type="text/javascript" charset="utf-8">
    function choose (el) {
        search = document.getElementById('search_done');
        search.value = document.getElementById('OptionA').value + " " + document.getElementById('OptionB').value + "&post_type=product";
    }
</script>

<form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">

<p>Food</p>
<select name='' id='OptionA' onchange="choose(this);">
  <option value=''selected='selected'>----</option>
  <option value="Sandwich">Sandwich</option>
  <option value="Hamburger">Hamburger</option>
</select> 



<p>Beverage</p>
<select name='' id='OptionB' onchange="choose(this);">
  <option value=''selected='selected'>----</option>
  <option value="Soda">Soda</option>
  <option value="Juice">Juice</option>
</select> 
   <input type="hidden" id="search_done" value="" name="s" />
   <input type="submit" id="searchsubmit" value="">

</form>
XmLmX2
  • 13
  • 8

1 Answers1

0

It seams like your script encodes the search values after the line you are referring to, thus resulting in your extra part being url encoded as well. Look for a line that says something like something = encodeURIComponent( search.value ) or something = encodeURI( search.value ). You will have to append your extra url data to the something variable after is has been encoded.

Andreas Hagen
  • 2,335
  • 2
  • 19
  • 34
  • Then you will need to post more code. You should make a jsfiddle =) – Andreas Hagen Mar 07 '13 at 11:04
  • Aha! You insert the data into a field that is url-encoded by the browser. Instead of appending to the string just add an extra field to you form. Something like `` should do it =) – Andreas Hagen Mar 07 '13 at 11:57