I'm setting up an autocomplete functionality and want to add an additional menu (not sure if menu is the right term). Similar to here:
Example 1 - Nike Example 2 - Kohls
Both examples have an additional menu that lists Product Suggestions.
I already have autocomplete functionality and I'm able to add images.
$(function () {
function log(message) {
$("<div>").text(message).appendTo("#log");
$("#cities").blur();
}
$("#cities").autocomplete({
source: function (request, response) {
$.ajax({
url: "index-46-sample.php",
data: {
keyword: request.term
},
dataType: 'json', // DON'T use jsonp !
cache: false,
success: function (data) {
console.log(data);
// Even on success, it may have no results...
if (typeof (data[0]) != "undefined") {
// Remove the no result error in case it's displayed
$("#noResult").css("display", "none");
// For fun, count it!
var count = 0;
while (data[count]) {
console.log(data[count]);
count++;
}
} else {
count = "NO";
// Display the no result error
$("#noResult").css("display", "inline");
}
console.log(count + " RESULTS");
// Pass the data to the dropdown!
response(data);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
});
},
minLength: 2,
select: function (event, ui) {
log(ui.item.value);
}
});
// Show results on input focus
$("#cities").on("focus", function () {
$("#ui-id-1").css("display", "block");
});
//highlights user input
$.ui.autocomplete.prototype._renderItem = function (ul, item) {
var term = this.term.split(' ').join('|');
var re = new RegExp("(" + term + ")", "gi");
var t = item.label.replace(re, "<b style='color: rgb(16, 141, 68)'>$&</b>");
return $("<li></li>")
.data("item.autocomplete", item)
.append("<div>" + t + "</div>")
.appendTo(ul);
}; });