SELECT object manipulation
SELECT object manipulation
by secretgspot
HTML
<div style="margin: 50px">
<select id="ken" multiple="multiple" size="5"></select>
</div>
JavaScript
var devices = [
{
DeviceID: 1,
DeviceName: 'Main Feeder'},
{
DeviceID: 2,
DeviceName: 'IT Load'},
{
DeviceID: 3,
DeviceName: 'Coffee Maker'},
{
DeviceID: 4,
DeviceName: 'Photocopier'},
];
jQuery.each(devices, function(index, item) {
var sel = jQuery("#ken").get(0);
var opt = new Option(item.DeviceName, item.DeviceID);
opt.selected = (item.DeviceID == 2);
sel.options[sel.options.length] = opt;
});