0

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.

itsMinij
  • 11
  • 2
  • 1
    Welcome to SO. It can be hard to come up with the right terms for searching, but please do try before posting a new question. I searched for "*jquery ui autocomplete highligh match*" and found answers here on SO already: https://stackoverflow.com/questions/7146588/how-to-highlight-jquery-autocomplete-results-that-match-the-text-already-typed, https://stackoverflow.com/questions/4107195/highlight-jquery-ui-autocomplete, https://stackoverflow.com/questions/9887032/how-to-highlight-input-words-in-autocomplete-jquery-ui, ... – Don't Panic Dec 23 '21 at 21:33
  • 1
    Does this answer your question? [How to highlight jQuery Autocomplete results that match the text already typed?](https://stackoverflow.com/questions/7146588/how-to-highlight-jquery-autocomplete-results-that-match-the-text-already-typed) – Don't Panic Dec 23 '21 at 21:33

0 Answers0