Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding many options to a select box - strange IE6 behavior

 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could anyone please explain the following oddity ?

I'm adding lots of <option> items into a <select> box.
'Lots' means about 2000 <option> items (ugly, but it's a requirement).
Addition is done dynamically using javascript.

Following advice on this forum, I used DOM (there *are* many other ways to do it, but let's please focus on DOM).
So, it's something like:


Now, this works pretty fast on firefox (takes less than 2 seconds on my machine), but it's very slow on IE6 (about 5-6 seconds).
The weird thing is, I *can* speed up IE6, if I append the options into a nested <optgroup> instead of directly into a <select> box
Namely, IE6 runs pretty fast if I add my options into something like:
<select>
<optgroup label='something' id='myGroup'>
</optgroup>
</select>

Could anyone please explain why <optgroup> makes such a difference in IE6 performance ?

Please see a live demo here:
View a live demo of my question

Thanks
[ May 03, 2007: Message edited by: Sol Mam-Orn ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without any knowledge of IE6 internals, hard to make any sort of guess.

So I'd say for IE6, use the optgroup!
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 seconds is not fast.

2000 is horrible U/X. You should categorized these.

I would suggest setting options.length then looping through the unset options and setting them. This approach has been supported for a long time.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this additional reply.

Categories would be great, only it would take my users a couple of months to debate the categories, meanwhile we're looking for 'fast and dirty' solutions.

Thanks a lot for the idea about setting existing options, i'll try it out
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, the old "Just get it done."

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript is not meant to do huge loops. I am sure some slower computers may give a message saying that the page is not responding.

Personally I would do an autocomplete or break up values alphabetically into lists. 2000 options is way to many thing for a person to go through, it needs to be small subsets.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic