Is there a way to change the options array of an html select list using javascript or mootools?
I need to replace the entire options set with a new one. In my ajax
Vanilla JS solution
var arrOptions = [];
arrOptions.push("");
arrOptions.push("");
arrOptions.push("");
document.getElementById("selectInput").innerHTML = arrOptions.join();
If you already have a set of options
var arrOptions = [];
var arrOptionsCollection = document.getElementById("check_typeInput").options;
for (var i=0, n = arrOptionsCollection.length; i < n; i++) { // looping over the options
if (arrOptionsCollection[i].value) {
arrOptions.push("");
}
}
arrOptions.push("");
arrOptions.push("");
document.getElementById("selectInput").innerHTML = arrOptions.join();