I have autocomplete select field for address and I am getting address from ajax call, in that I want to highlight one word from that address if it is present in the address. For example if I get address as- "Delhi India" then I want to highlight "India" in the dropdown. if I get address as- "Delhi", then it should display normally in dropdown.
$('#City').autocomplete({
source: function (request, response) {
$.ajax({
url: "GetAddress",
data: "{ 'address': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success:
function (data) {
response($.map(data, function (item) {
return {
label: item.address,
value: item.address
}
}));
},
error: function (jqXHR, textStatus, errorThrown) {
alert("error");
alert(jqXHR);
alert(textStatus);
alert(errorThrown);
}
})
}
});
In item.address I will have full address like- "Delhi India"
Can anyone suggest how I can check if the address contains India and if it contains then how can I highlight India only in the dropdown.