ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 64.2k

How to execute onchange before autocomplete where file number is match

Aug 30 2023 10:50 PM

I working on asp.net mvc . i face issue autcomplete execute before onchange on all cases 

I don't need that .

What I need is when employee id matched on database meaning exist only one on database 

then onchange working before autocomplete 

if more than one case what entered then display autocomplete 

as sample

if i have on employee id on database

1234590

1234591

1234592

so when write on input text box 1234 so will display 

1234590

1234591

1234592

and when write 1234590 

so no need to display autocomplete only display name based on fire onchange because it have only one value

this mean display onchange will fire on this case before autocomplete 

so How to do that please 

my scripts details

 $("#txtLineManagerId").autocomplete({
            source: function (request, response) {
                var searchText = $("#txtLineManagerId").val();
                console.log("search text" + searchText)
                $.ajax({
                    url: '@Url.Action("GetAllEmployeeBasedSearchText", "Resignation")',
                    data: { searchText: searchText },
                    method: "GET",
                    dataType: "json",
                    success: function (data) {

                        response($.map(data, function (item) {
                            console.log("data is" + item.EmployeeID);

                            return { label: item.EmployeeID, value: item.EmployeeID, employeeName: item.EmployeeName };

                        }))

                    }
                });
            },
            position: { my: "right top", at: "right bottom" },
            appendTo: '#searchContainer',
            select: function (event, ui) {
                // Update LineManagerName input with the selected Employee Name
                $("#LineManagerName").val(ui.item.employeeName);
                $("#selectedEmployeeName").val(ui.item.employeeName);
            },
            minLength: 4,

        });

                     $("#txtLineManagerId").change(function () {
            var employeeid = $("#txtLineManagerId").val();
            console.log("search text" + employeeid)
            $.ajax({
                url: '@Url.Action("GetEmployeeName", "Resignation")',
                data: { employeeid: employeeid },
                method: "GET",
                dataType: "json",
                success: function (data) {
                    $("#LineManagerName").val(data);
                    console.log("data is " + data);
                  

                }
            });

      });

 


Answers (1)