Issue when Changing Search Box Location
Posted: Sun Aug 13, 2017 5:37 am
I am having a hard time figuring this one out. So, I duplicated the default theme in order to create a custom one. I have moved the search box from the header to a new location and the search is not working at all. It is not getting the value for the search input field. How does the search box work?
Here is my 'search.twig' file:
Here is the 'javascript' code:
I have no clue what might be going wrong. Why is 'var value' returning empty? Can someone please help me out?
Here is my 'search.twig' file:
Code: Select all
<div id="search">
<input type="text" name="search" value="{{ search }}" placeholder="{{ text_search }}" />
<button type="button" class="search-btn">{{ text_search }}</button>
</div>
Code: Select all
$('#search input[name=\'search\']').parent().find('button').on('click', function() {
var url = $('base').attr('href') + 'index.php?route=product/search';
var value = $('#search input[name=\'search\']').val();
//console.log(value); //value is empty!!
if (value) {
url += '&search=' + encodeURIComponent(value);
}
location = url;
});