I\'m trying to create a datalist on they fly and attach it to an existing input element. But nothing happens (no dropdown arrow is shown) jQuery would be acceptable, too.
try below solution using jquery on change of input text its appending options.
$(document).ready(function() {
$("#search").on("input", function(e) {
var val = $(this).val();
if(val === "") return;
var arr = ['apple','banana','google','code','microsoft'];
var dataList = $("#searchresults");
dataList.empty();
if(arr.length) {
for(var i=0, len=arr.length; i").attr("value", arr[i]);
dataList.append(opt);
}
}
});
});
Example 1