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
HTML
Javascript
$("button").click(function(){
var oldSel = $('.element').get(0);
while (oldSel.options.length > 0) {
oldSel.remove(oldSel.options.length - 1);
}
var newSel = $('.newSel').get(0);
for (i = 0; i < newSel.length; i++)
{
var opt = document.createElement('option');
opt.text = newSel.options[i].text;
opt.value = newSel.options[i].value;
oldSel.add(opt, null);
}
})
Demo