Populate select box with key:value pair?

javascript, jquery

Solution

var opts = "0:SELECT ONE;1:VALUE1;2:VALUE2";
opts = opts.split(';');
var target = $("#targetSelectBox");
$.each(opts, function(i, opt){
  opt = opt.split(':');
  target.append($('<option />').val(opt[0].trim()).text(opt[1].trim()));
});

Problem

I am using jQuery and have server code returning the following values ``` 0:SELECT ONE;1:VALUE1;2:VALUE2 etc ``` How do I populate this into a select box? ``` var="0:SELECT ONE;1:VALUE1;2:VALUE2"; $("#targetSelectBox"). ??????? ```

Original source