javascript - Set jQuery Autocomplete on Textbox KeyDown Event - Stack Overflow

I want jQuery Autoplete on textbox key down eventI have tried below code, but it is not working.$("

I want jQuery Autoplete on textbox key down event

I have tried below code, but it is not working.

$("#txtName").keyDown({
    $("#txtName").autoplete({
        source: '@Url.Action("GetAllName", "Home")',
        select: function (event, ui) {
            $("#txtName").val(ui.item.value);
            return false;
        }
    });
});

I want jQuery Autoplete on textbox key down event

I have tried below code, but it is not working.

$("#txtName").keyDown({
    $("#txtName").autoplete({
        source: '@Url.Action("GetAllName", "Home")',
        select: function (event, ui) {
            $("#txtName").val(ui.item.value);
            return false;
        }
    });
});
Share Improve this question edited Sep 15, 2014 at 11:09 Ashley Medway 7,3097 gold badges53 silver badges73 bronze badges asked Sep 15, 2014 at 11:05 User5590User5590 1,4356 gold badges28 silver badges68 bronze badges 6
  • i think $("#txtName").autoplete() is sufficient no need for keyDown – Sandip Pingle Commented Sep 15, 2014 at 11:08
  • What does the MVC action look like? – Ashley Medway Commented Sep 15, 2014 at 11:08
  • You just want it to begin searching on the first keystroke? Try using minLength: 1. – DevlshOne Commented Sep 15, 2014 at 11:08
  • @SandipPingle $("#txtName").autoplete() is working. But i want functionality like, when i first click on textbox and press key down, then all the results should e – User5590 Commented Sep 15, 2014 at 11:10
  • @AshleyMedway Here i am using Url.Action. so Home is my controller and GetAllName is ActionName – User5590 Commented Sep 15, 2014 at 11:11
 |  Show 1 more ment

2 Answers 2

Reset to default 4

You do not need the keyDown event otherwise you are rebinding the autoplete on every keydown.

$("#txtName").autoplete({
    source: '@Url.Action("GetAllName", "Home")',
    select: function (event, ui) {
        $("#txtName").val(ui.item.value);
        return false;
    }
});

To show all results when one character is entered add minLength: 1

If what you want is to have all the items displayed when the textbox has focus then this is what you are looking for: https://stackoverflow./a/4604300/1398425

If you just want it to begin searching on the first keystroke, try using minLength: 1:

$("#txtName").autoplete({
    source: '@Url.Action("GetAllName", "Home")',
    minLength: 1,
    select: function (event, ui) {
        $("#txtName").val(ui.item.value);
        return false;
    }
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745292765a4620960.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信