Is it somehow possible to set a value (value/text as in a combobox) in jQuery UI Autocomplete?
I need to get a DB id from the selected item in the Autocomplete box.
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You really can’t, at least as far as I’ve seen, set a value in the jQueryUI autocomplete widget, but you can use the widget to set the value of an attribute in a hidden field or maybe an attribute on some other element.
Here’s a quick jsFiddle I put together to demostrate it. Hopefully this can help.
My example is based on the jQueryUI AutoComplete example for “Custom Data and Display”. Basically, it assumes you get some array of data back from a service or it’s rendered from the server-side. In your array of data, you have a display field, a key value and your DB ID. The key value really isn’t necessary. But when you select an item in your autocomplete list, you can capture what was selected in the autocomplete’s
selectevent and then handle the data appropriately. I stored the ‘id’ value in my array in a hidden field, but you can handle it differently.Hope this helps!