I have an array var myList = new Array(); and I have a drop down
@Html.DropDownList("yourList", Model.yourList).
How can I fill the dropdownlist using javascript.
var myList = new Array();
for (i=0; i<myList.length; i++) {
master.options[master.options.length]=new Option(myList[i].text, myList[i].value);
}
var myList = new Array();
myList.push({ value: '1', text: 'item 1' });
myList.push({ value: '2', text: 'item 2' });
myList.push({ value: '3', text: 'item 3' });
$('#yourList option').remove();
$.each(myList, function () {
$('<option/>', {
value: this.value,
html: this.text
}).appendTo('#yourList');
});