views:

343

answers:

2

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.

+1  A: 

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

Damien
+1  A: 

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);
karim79
ooo nicer........
Damien