Dave Crane wrote:
[...]
The easiest way to fix it is probably just to use the select elements options
property, and the add() method to add a new option object, something like:
var sel=$("TestSelect");
sel.add(new Option("apple",1));
This are DOM 1 standard stuff, supported in all browsers AFAIK.
For the record, new Option is DOM 0 (i.e. not part of the official W3C
DOM but implemented by every browser since about Navigator 2 and IE 3).
In DOM 1, the add method puts the new option at the head of the list of
options, in DOM 2 that was changed to the end of the list. I don't
know how many browsers implement the add method according to DOM 1, but
to be sure:
sel.options[sel.options.length] = new Option(...);
seems to be the commonly accepted method for adding option elements.
Also, IE has a few bugs in its implementation of the HTMLSelectElement
interface - with the add method, IE expects the optional second
argument to be a number (the index of the option to insert before)
whereas the W3C DOM HTML specification requires an object (a reference
to the option element to insert before). Therefore, if you want to add
the option at a particular place in the option list, you can't use the
add method unless you include a bunch more code with try..catch to sort
it out.
So to put the option in a particular place, use the DOM Core
insertBefore method.
You can use DOM Core methods to add options in IE, just that you have
to add the text property by appending a text node to the option element
(which works fine in other browsers too) rather than assign to its text
property.
var newOption = document.createElement('option');
newOption.value = '...';
newOption.appendChild(document.createTextNode('...'));
// Now add it to the select using whatever method suits
Using new Option is somewhat more appealing. :-)
--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---