I get the name of the form in the city form and show it using autocomplete.
function GetLocalityList() { var LocalityArray = []; $.post("MvcLayer/Index/GetLocalityList", { CityID: $('#sltCity').val() }, function(data) { // My sql query will be like this select LocalityID, CityID, LocalityName from tablename where CityID = 20 // Here (data) is array format. Like this // [{"LocalityID":9397,"CityID":55,"LocalityName":"Adugodi"},{"LocalityID":9398,"CityID":55,"LocalityName":"Aga Abbas Ali Road"},{"LocalityID":9399,"CityID":55,"LocalityName":"Agaram"},{"LocalityID":9400,"CityID":55,"LocalityName":"Agrahara Dasara Halli"},{"LocalityID":9401,"CityID":55,"LocalityName":"Agrahara Dasarahalli"},{"LocalityID":9402,"CityID":55,"LocalityName":"Airport Exit Road"},{"LocalityID":9403,"CityID":55,"LocalityName":"Horamavu"},{"LocalityID":9404,"CityID":55,"LocalityName":"Hosakere Halli"},{"LocalityID":9405,"CityID":55,"LocalityName":"Hennur"},{"LocalityID":9406,"CityID":55,"LocalityName":"Hesaraghatta"},{"LocalityID":9407,"CityID":55,"LocalityName":"HKP Road"},{"LocalityID":9408,"CityID":55,"LocalityName":"HMT Layout"},{"LocalityID":9409,"CityID":55,"LocalityName":"Hongasandra"},{"LocalityID":9410,"CityID":55,"LocalityName":"Hoody"},{"LocalityID":9411,"CityID":55,"LocalityName":"Hayes Road"} ] $.each(data, function(key, value) { LocalityArray[key] = value.LocalityName; }); $("#txtLocality" + SelectedTab).autocomplete({ minLength: 1, source: function(req, responseFn) { // \\b show each match letter in each word of list // ^ show each match letter in whole word of list var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(req.term), "i"); var a = $.grep(LocalityArray, function(item, index) { return matcher.test(item); }); responseFn(a); } }); }, 'json' ); }