RobB wrote:
[...]
as per RobG's comment...
Don't sweat it.
http://www.faqts.com/knowledge_base/...d/1600/fid/178
Since select.length is the same as select.options. length, why not
use:
select.length = 0;
Saves an entire 8 keystrokes. You can also use it to add options:
selectRef.lengt h += 10;
will add 10 empty options.
Seems my understanding re length being read only is out of date
(in regard to arrays and collections anyway). Since about
JavaScript 1.1:
"You can set the length property to truncate an array at
any time. When you extend an array by changing its length
property, the number of actual elements does not increase..."
<URL:http://synchro.net/docs/js/ref/array.html#1193 439>
Sun had some similar comments on options collections.
I could not find any reference on the W3C site to say that the
number of options can be modified by changing the length other
than this in their "issues to be resolved":
"From O'Reilly's JavaScript Definitive Guide book [p. 646]:
"[begin quote]
"If you set an element in the options[] array to null, then
that option will be removed from the Select object, and the
elements above it in the array will be moved down, changing
their indices, to occupy the new space in the array.
"If you create a new Option object with the Option()
constructor (see the Option reference entry), you can add that
option to the end of list of options in the Select object by
assigning the newly created option to a position at the end of
the options[] array. To do this, set options[options.length].
"[end quote]
"Additional ly, if you set options.length to a value higher than
the current value, then the number of options in the Select
object will be increased by adding new options to the end of
the array.
"Each of the browsers that I tested, Netscape, Win IE, Mac IE,
and WebTV, all work as above. I tested older versions of
browsers as well as the latest versions of these browsers."
<URL:http://www.w3.org/2001/12/DOM-Level-2-issues#i9b>
So I guess use length to modify arrays/collections all you like,
you should be able to extend and truncate arrays this way and can
use select.length or select.options. length (tested in IE and
Firefox).
--
Rob