<script type="text/javascript" src="jquery.ui.autocomplete.min.js" ></script>
<script type="text/javascript" src="jquery.ui.core.min.js" ></script>
<script type="text/javascript" src="jquery.ui.widget.min.js" ></script>
<script type="text/javascript" >
$(function () {
var cache = {}, lastXhr;
$("#Grid_RouteDetailCode_ftxtLocationName").autocomplete({
minLength: 1,
success: function (request, response) {
var term = request.term;
if (term in cache) {
response(cache[term]);
return;
}
lastXhr = $.getJSON("GetAutoComplete.aspx?&name=" + request.term, request, function (data, status, xhr) {
cache[term] = data;
if (xhr === lastXhr) {
response(data);
}
});
},
select: function (event, ui) {
document.getElementById("locationroute").value = ui.item.id;
}
});
});
and my json data from getautocomplete.aspx is
[
{
"id": "1",
"label": "KL CITY",
"value": "1"
},
{
"id": "2",
"label": "PETALING JAYA",
"value": "2"
},
{
"id": "3",
"label": "SUBANG JAYA",
"value": "3"
},
{
"id": "4",
"label": "SHAH ALAM",
"value": "4"
},
{
"id": "6",
"label": "BSDCB",
"value": "6"
},
{
"id": "7",
"label": "FWS",
"value": "7"
},
{
"id": "8",
"label": "HSGHA",
"value": "8"
}
]