I'm using the jQueryUI autocomplete widget to get data from a JSON web service. Its very similar to the example below:
<script>
$(function() {
$( "#city" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function( data ) {
response( $.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.id
}
}));
}
});
},
minLength: 2
});
});
</script>
My question is how can I control what is put into the input box (#city) when something is selected from the list. At the moment the autocomplete works well and will give a list of labels. However when you select one of the list items it puts the value into the input. In this case its an id that i want to use but I want the input to display the label data rather than the value data.