0

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/>
3
  • Checked your console for errors? Commented Nov 12, 2013 at 21:23
  • No errors , just value and key both coming as autocomplete suggestion.. Commented Nov 12, 2013 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. Commented Nov 12, 2013 at 21:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Now getting trigger the select option.but response values are not assigning to text field. Please advise.
Did you see my comment about preventDefault() above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.