John John
John John

Reputation: 1

Autocomplete Select is not firing

i have the following script inside my asp.net MVC razor view:-

$("#Technology2_Tag").autocomplete({
            minLength: 1, delay: 1000,
            source: function (request, response) {
                $.ajax({
                    url: "@Url.Content("~/Switch/AutoComplete2")",
                    dataType: "json",

                    data: {
                        term: request.term,
                        SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val(),
                    },
                    success: function (data) {
                        response(data);
                    },
                    select: function (event, ui) 
                    {
                        //get the value user selected
                        alert('t');
                        //your code populate data to dropdownlist...
                    }
                });
            },

        });

The autocomplete is working well, but the select is not firing, for example after selecting an autocomplete item , no alert will be shown ? can anyone advice ? Thanks

Upvotes: 0

Views: 67

Answers (1)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

It is placed inside ajax which is wrong,place it outside it like this:

$("#Technology2_Tag").autocomplete({
            minLength: 1, 
            delay: 1000,
            source: function (request, response) {
                $.ajax({
                    url: "@Url.Content("~/Switch/AutoComplete2")",
                    dataType: "json",

                    data: {
                        term: request.term,
                        SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val()
                    },
                    success: function (data) {
                        response(data);
                    }

                }); // <----------ending of ajax 
            }, //<------- ending bracket of source function
            select: function (event, ui) 
                    {
                        //get the value user selected
                        alert('t');
                        //your code populate data to dropdownlist...
                    }

        });

Upvotes: 1

Related Questions