Sometimes, we want to add an HTML select form with option to enter custom value.
In this article, we’ll look at how to add an HTML select form with option to enter custom value.
How to add an HTML select form with option to enter custom value?
To add an HTML select form with option to enter custom value, we use the input and datalist elements.
For instance, we write
<input type="text" list="cars" />
<datalist id="cars">
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</datalist>
to add an input and a datalist element that populates an autocomplete drop down with the options for the input.
We set the list attribute of the input to the id of the datalist element so that the choices in the datalist element is used as the options for the input.
Conclusion
To add an HTML select form with option to enter custom value, we use the input and datalist elements.