I'd like to create a text field with a dropdown list that lets the user choose some predefined values. The user should also be able to type a new value or select a predefined one from a dropdown list. I know that I can use two widgets for that but in my app it would be more ergonomnic if it was unified in a one widget.
Is there a standard widget or do I have to use a third party javascript?
How about browser portability?
The best way to do this is probably to use a third party library.
There's an implementation of what you're looking for in jQuery UI and in dojo. jQuery is more popular, but dojo allows you to declaratively define widgets in HTML, which sounds more like what you're looking for.
Which one you use will depend on your style, but both are developed for cross browser work, and both will be updated more often than copy and paste code.
This can be achieved with the help of plain HTML, CSS and JQuery. I have created a sample page:
I am not sure there is a way to do it automatically without javascript.
What you need is something which runs on the browser side to submit your form back to the server when they user makes a selection - hence, javascript.
Also, ensure you have an alternate means (i.e. a submit button) for those who have javascript turned off.
A good example: Combo-Box Viewer
I had even a more sophisticated combo-box yesterday, with this dhtmlxCombo , using ajax to retrieve pertinent values amongst large quantity of data.
ComboBox with TextBox (For Pre-defined Values as well as User-defined Values.)
ComboBox with TextBox (Click Here)
A little CSS and you are done fiddle
Very simple implementation (only basic functionality) based on CSS and one line of JS code
Please note: it uses previousElementSibling which is not supported in older browsers (below IE9)
Here it is on JSFiddle