I want to validate my input datalist so that it will only be submitted when one of the elements is selected from the list. If not submit then I want to give a red error message next to the input element so the user understands what he did wrong.
Example:
<input type="text" list="typ" name="name" placeholder="gtown" >
<datalist id="typ">
<select name="name">
<option value="atown">atown</option>
<option value="btown">btown</option>
<option value="ctown">ctown</option>
</select>
</datalist>
</input>
I wonder if it is possible with datalist?
If anyone can help me, I would be very grateful.
edit: I want to validate the code, it should now if it is on of the options or not, or when nothing was inputed, more like this answer I found Datalist option validation required however it give a pop up window, and I do not now how to show next to the input only a error message.
Edit2: I must not use an additional library.