Is there some type of plugin to do this? The server will return JSON content containing the option labels and values.
I can do this manually, I just wanted to see if there was an easier way.
Is there some type of plugin to do this? The server will return JSON content containing the option labels and values.
I can do this manually, I just wanted to see if there was an easier way.
I literally just loop though the items in the list, and generate the html, before inserting the html into the element. There is probably a plugin now you mention it.
var selectHtml = ''
foreach obj Item in jsonobject.list)
selecthtml += "<option value="+ item.value +">" + item.label + "</option>"
$('selectList').html(selectHtml);
Or something similar
Loop through the json and do this on each text/value pair (works cross-browser nicely):
var opt = document.createElement('option');
opt.value = "someValue";
opt.appendChild(document.createTextNode("someText"));
$('#mySelect').append(opt);