This is for a multi select box, so the user needs to select multiple items in one box.The for loop in the ajax will be different then in a drop down list. i Have JSON data which contains name, address etc. I also have in html a multi select box:
<select name="AccountDetails" id="Accounts"
multiple>
<option value="Name">Name</option>
</select>
I want to populate this multi select box from the JSON data, but i am not sure how.
I tried this:
$.ajax({
url: baseUrl + "accounts",
method: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
accept: "application/json",
success: function (returnData) {
var data = returnData.value;
for (var i = 0; i < data.length; i++) {
AccountDetails += "<option value='" + data[i].accountid + "'>" + data[i].name "</option>";
}
$(document).ready(function () {
var AccountDetails = '<option selected="selected" value="0">- Select -</option>';
$("#Accounts").html(AccountDetails);
$(".nav > ul").show();
},
error: function (msg) {
console.log(msg);
}
});
}