Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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/>
share|improve this question
    
Checked your console for errors? –  j08691 Nov 12 '13 at 21:23
    
No errors , just value and key both coming as autocomplete suggestion.. –  user2957598 Nov 12 '13 at 21:24
    
Are you sure you want to preventDefault() in select()? Per the API, that will prevent that value from being filled in in the text field. –  Russell Zahniser Nov 12 '13 at 21:27

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Now getting trigger the select option.but response values are not assigning to text field. Please advise. –  user2957598 Nov 12 '13 at 22:09
    
Did you see my comment about preventDefault() above? –  Russell Zahniser Nov 13 '13 at 2:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.