javascript array from datalist code example

Example 1: javascript array from datalist

var options = document.getElementById('estados').getElementsByTagName('option');
var optionVals = [], i = 0;

for (i; i < options.length; i += 1) {
  optionVals.push(options[i].value);
}

console.log(optionVals);

Example 2: create javascript array from datalist dynamically

var my_list=document.getElementById("months");
my_list.innerHTML = str;

Example 3: create javascript array from datalist dynamically

<input name="month" list="months" >
<datalist id="months" >
</datalist>

Example 4: create javascript array from datalist dynamically

alert(my_list.options[5].value);

Tags:

Misc Example