jQuery: Take a List and Populate a Select Drop Down List

8/25/2015 4:11:15 PM

Use jQuery to remove options from a SELECT object and add each item from a list to a SELECT object.

//get select object
var selectObject = $("#ddlCountryList");

//remove previous values - optional
$(selectObject).find("option").remove();

//append new values
$.each(array_of_countries, function()
{
    selectObject.append($("<option />").val(this.CountryId).text(this.CountryName));
});