Reputation: 409
I'm (pretty) new to JQuery, but have been reading page after page on the autocomplete feature. I cannot get the select event to trigger when selecting an item from the drop-down list.
This is the code:
$("#newTag").autocomplete({
source: function(request, response) {
$.ajax({
url: "ajax",
datatype: "json",
type: "POST",
data: {searchText: request.term},
success: function(data, textStatus, jqXHR) {
response($.map(data, function(item) {
return {
label: item.tag,
id: item.id
};
}));
},
select: function(event,ui) {
alert("Selected ");
}
});
}
});
It returns the right data from the ajax call, so that seems to work fine. I have made an example searching through an array, which worked fine. But I cannot seem to find the error in the above code.
All help is highly appreciated.
Upvotes: 2
Views: 280
Reputation: 97672
Your select property is on the ajax call not the autocomplete
$("#newTag").autocomplete({
source: function(request, response) {
$.ajax({
url: "ajax",
datatype: "json",
type: "POST",
data: {searchText: request.term},
success: function(data, textStatus, jqXHR) {
response($.map(data, function(item) {
return {
label: item.tag,
id: item.id
};
}));
}
});
},
select: function(event,ui) {
alert("Selected ");
}
});
Upvotes: 1