I need to get the content (text, not value) of the datalist option selected by the user OR some other content written by the user even that content don't match with the content of any options.
And I want to put the content inside a variable.
Thanks.
<input type="text" id="input-color" list="color" autocomplete="off" required >
<datalist id="color">
<option>WHITE</option>
<option>BLACK</option>
<option>BLUE</option>
<option value=" ">(Please, inform some color.)</option>
</datalist>
I'd like a quite simple solution because I am a novice programmer.
You can add an event listener to the input event that detects the input type (option selected or plain input) and then read the value of the element with id "input-color".
Demo:
See also: Perform action when clicking HTML5 datalist option)