开发者

With jquery autocomplete widget, how to populate the input value after a selection with my own data

开发者 https://www.devze.com 2023-03-31 17:16 出处:网络
In my form text input bar, t开发者_开发知识库he json returned by the autocomplete widget will be, [{id = 1,lable=\"lable1\"},......]

In my form text input bar, t开发者_开发知识库he json returned by the autocomplete widget will be, [{id = 1,lable="lable1"},......]

[{id = 1,label="label1"},{id = 2, label="label2"},......]

and I want the input box display value to be "label" which works as default, but I want to the input value to be "id" when I submit the form..

Many thanks!


I usually keep a <input type='hidden'> right next to the autocomplete input, and then on the select event of the complete I populate that with the ID:

 $("#autocomplete-input").autocomplete({
            minLength: 2,
            select: function (event, ui) {
                $("#autocomplete-input-id").val(ui.item.id);
            }

        }); 
0

精彩评论

暂无评论...
验证码 换一张
取 消