Search

var theTextQuery = ”; const autocompleteSearch = autocomplete({ container: ‘.home-search-bar__input’, placeholder: ‘Search’, openOnFocus: false, plugins: [querySuggestionsPlugin], onStateChange({ state }) { // On search field update theTextQuery = state.query; // update the theTextQuery variable }, }); $(‘.home-search-bar__submit’).on(‘click’, function (e) { e.preventDefault(); var baseUrl = $(this).attr(‘href’); // the href must be the one from the search result page var endUrl = baseUrl + theTextQuery; // the updated url which will look like https://your-site.com/your-result-page/?your-algolia-index[query]=the-query if (theTextQuery != ”) { // if search inout field is not empty console.log(endUrl); window.location = endUrl; // go to page result with the search query in the url } });
Skip to content