I need some jquery plugin as they use it on most flight booking sites where you have to choose your departure/arrival airport from a combolist.
i had a look around, but i could not really find any good solution. I need a autocomplete combobox that will stay open until the user chooses a item from a list of possible values, and it must support some hidden id numbers that will be send instead of the text – the plugins on jquery usually only send the text-value.
Right now i use http://blog.idealmind.com.br/geral/simple-autocomplete-jquery-plugin/ – but the issue with this is that user can enter anything that is not on the list via keyboard.
Are there a better plugins out there i could use? i’m not really much of a jquery or js programmer myself…
You have two different questions here.
Sending hidden IDs should be done using an array of objects with both a value and label attribute in your source. You’ll need to use the select and focus options to support this. http://jqueryui.com/demos/autocomplete/#custom-data
Forcing the user to select a valid option could be done a few ways. I like the idea of blanking the input box if the user types in an invalid option and then leaves the box. You can do this using the “change” option. This is what James’ code does too.
Here is a working example with both features:
http://jsfiddle.net/vZeHr/4/