如何获取自动填充文本框值

时间:2013-11-11 13:46:16

标签: jquery jquery-ui jquery-ui-autocomplete

我正在使用jquery auotcomplete功能。我已将此应用于以特定id开头的所有文本框,并根据当前文本框值过滤响应。但是没有得到价值。以下是我的代码。

$("input[id^='TextBoxAssociate']").autocomplete(
    {
        source: function (request, response) {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "CreateEditRequest.aspx/GetEmpNames",
                data: "{'empName':'" + $(this).val() + "'}", // here $(this) is ajax context, I want value of current textbox
                dataType: "json",
                success: function (data) {
                    response($.map(data.d, function (el) {
                        return {
                            label: el.EmpName,
                            value: el.EmpId
                        };
                    }));
                },
                error: function (result) {
                    alert("Error");
                }
            });
        }

1 个答案:

答案 0 :(得分:0)

    $("input[id^='TextBoxAssociate']").autocomplete(
        {
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "CreateEditRequest.aspx/GetEmpNames",
                    data: "{'empName':'" + $(this).val() + "'}", // here $(this) is ajax context, I want value of current textbox
                    dataType: "json",
                    success: function (data) {
                        response($.map(data.d, function (el) {
                            return {
                                label: el.EmpName,
                                value: el.EmpId
                            };
                        }));
                    },
                    error: function (result) {
                        alert("Error");
                    },
    select: function (event, ui) {
            var label = ui.item.label;
            var value = ui.item.value;
alert('Label : ' + label );
alert('Value : ' + value );
        }
                });
            }