• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's Wrong With My Select.add()

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep receiving type mismatch exception from my Select.add() call. What's wrong with it? Is this function supported by IE6?

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no [edit]need for the[/edit] add(), the line ...[....options.length]= newOpt; adds it.

Eric
[ January 18, 2007: Message edited by: Eric Pascarello ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In IE, the add() method for the select element doesn't follow the W3C rules. You may need to tinker with the parameters that you pass to it to get it to work.

What is the specific error that you are getting, and what exactly are you trying to do?
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean IE6 doesn't support Select.add()? But I do get such a function in ie6 by:



And HTMLSelectElement interface of DOM Level2 does define such a method. I get the type mismatch problem when using such a method rather than exception related to undefined method.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alec Lee:
You mean IE6 doesn't support Select.add()?


Yes, it does. But it's weird about how it interprets the 2nd parameter.

For example, if you are trying to add the option to the end of the list, the W3C Specification states that you should pass null. But IE6 requires a zero. Stuff like that.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I am looking for a way to insert a new option at the START of the option list. It seems that if I want to directly modify the options[] array, I can only append an element at the end of it by 'options[options.length]=new Option(..)' or overwrite another option by 'options[0]=sth'. This codes result in typeerror exception:


BTW, where can I find the microsoft's spec on its select.add() method?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried using 0 or 1, rather than an option reference, as the 2nd param?

It's been a while since I've played with this, but I remeber having to branch the code to keep IE happy.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah so you want to put it at the top! Yes you need to use add. Guess I miss that when I just wake up the night after a release.



W3C standards wat requires the option reference while IE needs a number. [edit] and yes Bear was right that you have to use a number with IE [/edit]

Eric
[ January 18, 2007: Message edited by: Eric Pascarello ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just did some testing and it appears that specifying 0 for IE does what you wish.

So I was remembering incorrectly earlier. To get it at the end of the list, you omit the 2nd param.

Note that this is only for IE. In real browsers, you follow the W3C Spec and use an element reference or null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic