简体   繁体   中英

Set Value of AutoComplete Textbox

application in MVC fraework.

from list of employee grid when user click on Edit button particular employee data would get display in the page. i have added one autocomplete textbox for users

i want to set autocomplete value based on clicked employee data.

$("#autoAssginedTo").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "/LeadGeneration/GetUsers",
                    type: "GET",
                    dataType: "json",
                    data: { Prefix: request.term },
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item.FirstName + ' ' + item.LastName, value: item.FirstName + ' ' + item.LastName, val: item.ID };
                        }))

                    }
                })
            },
            messages: {
                noResults: "", results: ""
            },
            select: function (e, i) {
                $("#AssignedTo").val(i.item.val);
            },
        });

i tried following :

 function setAutocompletCurrentValue(id, value) {
        $(id).val(value);
        var textToShow = $(id).find(":selected").text();
        $(id).parent().find("span").find("input").val(textToShow);
    }

but it sets id of user. i want to set employee name associated with empId

how to do that ?

Instead of this:

 $("#AssignedTo").val(i.item.val);

Replace it with this one:

$("#AssignedTo").val(i.item.label);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM