views:

134

answers:

1

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()));
}
+1  A: 

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

Jonathan Sampson
Thanks but even with the ; it did not work.
Shah
@shah-bc: See my functional example link a the bottom of my post.
Jonathan Sampson
removing the trim worked! thanks a lot.
Shah
Firefox provides a String.trim() method in its javascript while IE does not.
Lance McNearney