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

血红的双手。 提交于 2019-12-11 07:47:15

问题


In my form text input bar, the 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!


回答1:


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);
            }

        }); 


来源:https://stackoverflow.com/questions/7213132/with-jquery-autocomplete-widget-how-to-populate-the-input-value-after-a-selecti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!