I would like have a field that shows a set of pre-defined options to choose from, but also for the user to add their own entry if none of the options apply, i.e.
Option 1
Option 2
Option 3
Other (please specify)
I have a look at using an input field with the new DATALIST. It’s not quite ideal, because users don’t see the full list of choices once they start typing. And they might not even realise that there are pre-defined choices.
Hi, you can simply use HTML <OPTION> tags to generate your predefined list and have a “Other” option tag. When users click on other option tag, a text box will appear where users can specify their own. Lets look at the code.
function check(select,text){
var index = document.getElementById(select).selectedIndex;
if(index==4){
document.getElementById(text).style.display=“block”;
} else {
document.getElementById(text).style.display=“none”;
}
Agreed with Rani, I would use something like this before messing with datalist simply because of browser support (so you’d be using Javascript anyway).
Only thing I’d add to Rani’s code is, on the display:none input, I’d add aria-role=alert which in many (but not all yet) browsers will work to read the text of the input once it’s become visible.
When I made a datalist example a few years ago, in Opera if the user focussed on the input, the possibilities all showed. Later, in webkit you had to down-arrow, which would mean many users would have no idea there were pre-written options. At the time I don’t believe anyone else supported it.