$(document).ready(function() { $select_options = $('#searchbox').selectize({ valueField: 'url', labelField: 'name', //searchField: ['name','description'], searchField: ['name'], maxOptions: 10, options: [], create: false, persist: false, render: { option: function(item, escape) { return '
'+escape(item.name)+'
'; } }, optgroups: [ {value: 'deal', label: 'Deals'}, {value: 'category', label: 'Categories'} ], optgroupField: 'class', optgroupOrder: ['deal','category'], load: function(query, callback) { if (!query.length) return callback(); $.ajax({ url: '/search/get', type: 'GET', dataType: 'json', data: { keywords: query.trim(), category: $("#search-category").val() }, error: function() { callback(); }, success: function(res) { callback(res.data); } }); }, onChange: function(){ window.location = this.items[0]; } }); $('.selectize-dropdown-content').after('See More'); $('.selectize-input').append(''); var param1var = getQueryVariable("keywords"); $(".selectize-input input").val(param1var); $("#search-category").selectmenu({change: function( event, ui ) { var selectize = $("#searchbox")[0].selectize; selectize.clear(); selectize.clearOptions(); }}); $('.selectize-input').keypress(function(e) { if(e.keyCode == 13){ $("#searchbox option:selected").val($(".selectize-input input").val().trim()); $('#searchbox-form').submit(); } }); }); function searchSubmit() { $("#searchbox option:selected").val($(".selectize-input input").val().trim()); $('#searchbox-form').submit(); } function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i