I've a question for you ...
I've a function for autocomplete some text and on select i want return 2 value from the function ... this is my code:
function autoComp(field, srt, file, act) {
$( field ).autocomplete({
minLength: srt,
source: function( request, response ) {
$.ajax({
url: file,
type: 'post',
dataType: "json",
data: {'azione':act, 'txt':request.term},
success: function(data) {
response( $.map( data.result, function( item ) {
return {
label: item.text,
value: item.text,
id: item.id
}
}));
}
});
},
select: function( event, ui ) {
var obj = {};
obj[0] = ui.item.id;
obj[1] = ui.item.label;
return obj;
}
});
}
$(document).on('focus', '.farmCompl', function(){
obj = autoComp(this, 3, 'search.php', 'music');
if(obj){
alert(obj[0]);
alert(obj[1]);
}
});
autoComp(...) wants to be a general function that is called from many places in my project .... 'field' is the selector to be completed (ex. '#text1'), srt is the start of automplete .... Ajax works correctly in fact autocomplete presents the database options ... The problem is on the selection of the option .... When I select the option, I want that autocomplete return the values of id and label to the function or the event that called autoComp(...) I hope to have been clear Bye