I have a currently functioning input that correctly searches through a JSON array and displays content based on whats selected. However, I am trying to add functionality to the search tool that will allow it to accept a query string in the URL.
ie: "site.com?s=test" would fill input and search for "test"
I am able to correctly decode the URI, and pass the variable to the input. However, it does not 'search' and actually requires deleting a character and retyping it in for it to accept the search term.
This is the jQuery autocomplete I am using: https://github.com/devbridge/jQuery-Autocomplete
I will also note, I can paste the search term into the input and it will search, but if it grabs the value from the URL it seems to ignore the search function.
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
$("#input").val(urlParams["s"]);
$("#input").autocomplete({
lookup: names,
onSelect: function (suggestion) {
// code here for output
}
});
Not sure what I am missing.
jfyi - question tag keeps defaulting to jquery-ui-autocomplete instead of jquery-autocomplete. Sorry for the confusion.