Add Options to a Select with jQuery : IE7

| | Comments (2) | TrackBacks (0)

Problem: trying to add a new option to a select drop-down menu doesn't display the text in IE7.

Solution:

var thisValue = 12;
var thisText  = 'December';
var thisOpt   = document.createElement('option');
thisOpt.value = theValue;
thisOpt.appendChild(document.createTextNode(thisText));

$(".months_menu").append(thisOpt);

0 TrackBacks

Listed below are links to blogs that reference this entry: Add Options to a Select with jQuery : IE7.

TrackBack URL for this entry: http://www.robbiebow.co.uk/mt/mt-tb.cgi/70

2 Comments

steve said:

I'm not sure how the append() method in jQuery works, but if it just wraps this type of structure, then you've encountered an IE bug (274 to be exact)

http://webbugtrack.blogspot.com/2007/08/bug-274-dom-methods-on-select-lists.html

e.g. if .append(str) translates to:

this.append = function(str){
this.innerHTML = str;
};

In IE you can't set the .innerHTML on a select element. you'll need to use the DOM zero style "new Option();" syntax. Or set the outerHTML.

Robbie Bow Author Profile Page said:

I don't know how .append() works under the hood either, but I did try creating an option object using the "new Option()" syntax That result in the option being added but the text was not displayed.My only luck was with the createElement() - appendChild(createTextNode) syntax above.

Leave a comment

About this Entry

This page contains a single entry by Robbie Bow published on August 7, 2008 7:59 PM.

MySQL: Selecting non-unique records was the previous entry in this blog.

Sample iptables config for a web server is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.21-en