Hi,
I have implemented jquery autocomplete to a textbox. here is the code.
$("#txtState").autocomplete({
source: function (request, response) {
$.ajax({
url: '@Url.Action("StateLookup", "PatientDemographic", "")', type: "POST", dataType: "json",
data: { searchText: request.term, maxResults: 10 },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Text, value: item.Text, id: item.Value }
}))
}
})
},
select: function (event, ui) {
// alert(ui.item ? ("You picked '" + ui.item.label + "' with an ID of " + ui.item.id)
// : "Nothing selected, input was " + this.value);
$("#StateCode").val(ui.item.id);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
----------------------------------------------------------------------------------------
Lets say the results are "Apple" , "Banana", "Cabbage". I always want the default value as "Banana" while rendering page. how do i customize and set default value to "txtState" ?