Several errors in your code:
Datalist
The
<datalist>
cannot be nested inside the
<input>
:
<input id="zeInput" type="text" list="typ" name="name" placeholder="gtown" />
<datalist id="typ">
<option value="atown">atown</option>
<option value="btown">btown</option>
<option value="ctown">ctown</option>
</datalist>
Each
You can't use
allowedValues.each(fn)
; you have to use
$.each(allowedValues, fn)
:
$.each(allowedValues, function(index, element) {
jQuery.each() | jQuery API Documentation[
^]
Value
The jQuery object doesn't contain a property called
value
; you need to use the
val()
method instead:
if (element === input.val()) {
.val() | jQuery API Documentation[
^]
Also, calling
.attr("style", "...")
will
overwrite the element's style. To change an individual style, use
the css()
method[
^] instead:
msg.css("color", "green");
...
msg.css("color", "red");
...
msg.css("display", "inline");
Demo[
^]