Ajax autocomplete response values are not coming to select option to display the text in the filed. Please advise how to get the value in select event.
$("#parts").autocomplete({
source: function(request, response) {
$.ajax({
url: "searchPart.jsp",
type: "POST",
dataType: "json",
data: { name: request.term},
success: function (data) {
tempResults = data;
response($.map(data, function (value, key) {
return {
label: key,
value: key
};
}));
}
});
},
minLength: 3,
select: function (event, ui) {
//event.preventDefault();
var name = tempResults[ui.item.value].value;
var id = tempResults[ui.item.value].key;
$('#partname').val(name);
$('#partname').text(name);
}
});
</script>
</head>
<body>
<form>
<input type="text" name="part" id="parts" />
<input type="text" name="partname" id=partname/>