I need some jquery plugin as they use it on most flight booking sites where you have to choose your departure/arrival airport from a combolist.
i had a look around, but
The plugin by jQuery UI actually allows you to send through a text value and an integer as return types.
Here is the general code I use for auto completes.
$("#c_where").autocomplete({
autoFill: true,
mustMatch: true,
selectFirst: true,
source: function(request, response) {
$.ajax({
type: "post",
url: "inc/ajax/json/hotels.php", // Upload this aswell
data: {
maxRows: 12,
term: request.term
},
success: function(data) {
response($.map(JSON.parse(data), function(item) {
return {
label: item.name,
value: item.name,
id: item.hid
}
}));
}
});
},
change: function(event, ui) {
/*if ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0) {
$(this).val('');
}*/
if (!ui.item) {
$(this).val('');
}
},
select: function(event, ui) {
$('#c_where').data("id", ui.item.id);
}
}).live('keydown', function (e) {
var keyCode = e.keyCode || e.which;
if((keyCode == 9 || keyCode == 13) && ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0)) {
$(this).val($(".ui-autocomplete li:visible:first").text());
}
});