I have written autocomplete function using keyup but when clicking outside autofill dropdown doesnt hide. autofill search in database and fill the data and show it. i have used wordpress
jQuery("#edit-full-name").keyup(function(e) {
jQuery("#fullnamelist").empty();
if (e.which == 8 || e.which == 46) return false;
jQuery.ajax({
type: "POST",
url: my_ajax_object.ajax_url,
dataType: "json",
data: {
action: 'autocomplete_name',
text: jQuery(this).val(),
},
beforeSend: function() {
jQuery("#edit-full-name").css("background", '#FFF url(' + my_ajax_object.theme_path + '/LoaderIcon.gif) no-repeat 165px');
},
complete: function() {
jQuery("#edit-full-name").css("visibility", "hidden");
},
cache: false,
success: function(data) {
jQuery("#fullnamelist").empty();
jQuery.each(data, function(i, obj) {
jQuery("#fullnamelist").append('<li>' + obj + '</li>');
})
jQuery("#fullnamelist li").bind("click", function() {
setText(this);
});
},
complete: function() {
jQuery("#edit-full-name").removeAttr("style");
}
})
})