Im trying to create autocomplete text box, I have an issue with my jquery. Please correct me where im missing.
- Names are not displaying in the suggestion list
- When i select the name, i need to place the cityid for the selected city in html hidden input field.
- Is there any way to change the suggestion list design.
Here is the code I have tried:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function () {
var arr_text = [{"cityid":20,"city":"city1"},{"cityid":21,"city":"city2"},{"cityid":22,"city":"city3"}]
$("#txtauto").autocomplete({
source: function (request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
var matching = $.grep(arr_text, function (value) {
var name = value.city;
var id = value.cityid;
return matcher.test(name) || matcher.test(id);
});
response(matching);
}
});
});
</script>
</head>
<body>
<div class="ui-widget">
<form>
<label for="txtauto">Autocomplete</label>
<input id="txtauto" />
</form>
</div>
</body>
</html>

Hi Use response like below.