开发者

jQuery autocomplete - associating another value with selection

I'm building a jquery function that pulls from a database in order to allow users to select a location. These locations have two relevant columns: Name, city and ID.

Currently I have it setup so that the autoselection displays Name + City as the text for the user. How do I associate that row's ID with the text? So开发者_如何学C that the user can select their location by name and city - but I have the ID of the club they've selected in either a hidden field on in the actual tag?


Within the autocomplete plugin there is the ability to pass the custom data which is then stored in the jQuery data object on each element and passed as parameters on various callbacks. You can take a look at this example in the docs, you'll find what your looking for there.


You can use the official HTML5 "data-{your name}" attribute to store the ID. The "data-" attribute won't be overridden at any time in the near future according to the HTML5 spec.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜