Question

this code works fine in FF, not in IE.

var target = $("#targetSelectBox")
var vals   = values.split(";");
for (var i = 0; i < vals.length; i++) {
        var parts = vals[i].split(":");
 target.append($('<option />').val(parts[0].trim()).text(parts[1].trim()));
}
Was it helpful?

Solution

You're missing a semi-colon after the first line:

var target = $("#targetSelectBox")//;

Be sure that this selector is actually finding your element:

<select id="targetSelectBox">
  <!-- options to come -->
</select>

We'll also need to see the full portion of your code, including what values is to begin with. Additionally, make sure that jQuery is properly referenced, and you might even consider wrapper your inner target reference in the jQuery wrapper as well:

var newOption = $("<option>").val( parts[0] ).text( parts[1] );
$(target).append(newOption);

Functional example online: http://jsbin.com/ibeci/edit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top