JQuery UI autocomplete with values

Is it possible to set a value (value / text as in a combo box) in jQuery user interface autocomplete?

I need to get the DB id from the selected item in the Autocomplete field.

Thanks in advance!

+6
jquery autocomplete
source share
1 answer

You really cannot, at least as far as I know, set the value in jQueryUI autocomplete widgets, but you can use the widget to set the attribute value in a hidden field or maybe an attribute on some other element.

Here's a quick jsFiddle. I put it together to demonstrate it. Hope this can help.

My example is based on jQueryUI autocomplete for "User data and display". Basically, it is assumed that you will get some data from the service or displayed from the server. Your dataset has a display field, a key value, and your database identifier. The key value is really not required. But when you select an item in the autocomplete list, you can capture what was selected in the autocomplete select event, and then process the data accordingly. I saved the id value in my array in a hidden field, but you can handle it differently.

Hope this helps!

+26
source share

All Articles