user2957598
user2957598

Reputation: 121

Jquery autocomplete select event issue

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/>

Upvotes: 0

Views: 628

Answers (1)

Russell Zahniser
Russell Zahniser

Reputation: 16354

Your select() event handler is in the ajax() call, not the autocomplete() call. If you tell your editor to fix your indentation that will be obvious.

Upvotes: 1

Related Questions