HighDots Forums  

Re: Writing Arrays To <select> Tag

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Writing Arrays To <select> Tag in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stanimir Stamenkov
 
Posts: n/a

Default Re: Writing Arrays To <select> Tag - 06-21-2008 , 07:59 AM






Sat, 21 Jun 2008 05:26:33 -0700 (PDT), /Bart Van der Donck/:

Quote:
Info about the 'Option'-object:
http://www.javascriptkit.com/jsref/s...shtml#section2
I've always wondered how standard (official or not) is the Option
object? I mean isn't it better to use
Document.createElement("option") and the add() / remove() methods of
the HTMLSelectElement [1], or probably just Node.appendChild() /
Node.removeChild()? I've not found references to the Option object
in the "Gecko DOM Reference" [2] and the MSDN Library [3] - have I
missed them?

[1] http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-94282980
[2] http://developer.mozilla.org/en/docs..._DOM_Reference
[3] http://msdn.microsoft.com/library

--
Stanimir


Reply With Quote
  #2  
Old   
Bart Van der Donck
 
Posts: n/a

Default Re: Writing Arrays To <select> Tag - 06-21-2008 , 09:51 AM






Stanimir Stamenkov wrote:

Quote:
Sat, 21 Jun 2008 05:26:33 -0700 (PDT), /Bart Van der Donck/:

Info about the 'Option'-object:
http://www.javascriptkit.com/jsref/s...shtml#section2

I've always wondered how standard (official or not) is the Option
object?
The Option-object is one of the eldest around and was already
supported in the first j(ava)script versions.

Quote:
I mean isn't it better to use Document.createElement("option")
and the add() / remove() methods of the HTMLSelectElement [1],
or probably just Node.appendChild() / Node.removeChild()? *
This belongs to a more recent coding style, which aims to advocate a
more general syntax. The benefit is that it's intended for the whole
DOM of the page, and thus technically easier for the programmer. On
the other hand, some could prefer a more classical approach too:
longer proven history, better browser support, programmer is more
confident in his old syntax, ...

Quote:
I've not found references to the Option object in the "Gecko DOM
Reference" [2] and the MSDN Library [3] - have I missed them?
Yes.

--
Bart


Reply With Quote
  #3  
Old   
Richard Cornford
 
Posts: n/a

Default Re: Writing Arrays To <select> Tag - 06-21-2008 , 12:45 PM



Stanimir Stamenkov wrote:
Quote:
Sat, 21 Jun 2008 05:26:33 -0700 (PDT), /Bart Van der Donck/:

Info about the 'Option'-object:
http://www.javascriptkit.com/jsref/s...shtml#section2

I've always wondered how standard (official or not) is the
Option object?
The code formulation proposed by Bart is the most consistent, widely
supported and reliable approach to adding options to a SELECT element
that has ever existed. And its widespread use means that it is unlikely
to stop being so in the foreseeable future.

The existence of a global - Option - constructor is not standardised
anywhere, but only one scriptable web browser has been observed not to
provide it (and that browser also did not provide - createElement - so
there was no alternative; you simply could not add OPTION elements to a
SELECT element in that environment).

Quote:
I mean isn't it better to use Document.createElement("option")
Even some very non-dynamic browsers, where - document.createElement -
either did not exist or was a pre-standardisation method with
limited/divergent capabilities/behaviour, sill provided an Option
constructor and the ability to dynamically manipulate the - options -
collection of a SELECT element.

Quote:
and the add() / remove() methods of the HTMLSelectElement [1],
The - add - and - remove - methods of the HTMLSelectElement interface
were a specification f**k-up that rendered them problematic from the
outset. The HTML DOM designers did not fully appreciate the consequences
of using the names of methods that had already been implemented on
pre-existing SELECT element implementations and they ended up
specifying - add - and - remove - with argument that did not correspond
with the pre-existing methods. Unfortunately, the pre-existing methods
were in IE 4 and that left Microsoft in the position of either ignoring
the standard or risking breaking existing intranet applications
belonging to their corporate customers. Microsoft chose the easy,
pragmatic and expedient option of not modifying their existing code to
be in line with the W3C HTML DOM specification.

That issue could have been completely avoided if the specification
designers had done nothing more than chosen different names for the
methods (such as - addOption -, etc.), but sometimes you get the
impression that the people working for the W3C are more interested in
creating new sticks to beat Microsoft with than they are in facilitating
the possibility of scripting web browsers using a one-code-fit-all
approach. (Whiteness the recent work on standardising -
offsetWidth/Height/Top/Left/Parent -in a way that Microsoft will not be
happy to implement (again because the change will break many of the
intranet applications belonging to its corporate customers)).

Quote:
or probably just Node.appendChild() / Node.removeChild()?
Historically the - appendChild - and - removeChild - methods (and
indeed - innerHTML - manipulation) have produced very inconsistent
outcomes when applied to OPTION and SELECT elements. As I recall IE 5
was particularly problematic in that regard, but not alone is exhibiting
issues.

Quote:
I've not found references to the Option object in the "Gecko
DOM Reference" [2] and the MSDN Library [3] - have I missed them?
You should realise that, while better than not having any documentation,
manufacturer documentation tends to stress how its authors think things
should be done in their own products, but say little about how things
should be done in order to be cross-browsers. It is quite likely that
many of these authors have little or no experience of cross-browser work
and so could not produce better examples even if they wanted to.
Microsoft's documentation has been particularly problematic in that
regard as its authors are very keen to show examples littered with
constructs that have tended to work only in IE browsers (or close
imitators), such as referencing members of DOM collections by calling
the collection, i.e:-

document.forms('formName').elements('controlName') ;

- where:-

document.forms['formName'].elements['controlName'];

- would have been as effective in IE browsers and could be expected to
also work in all W3C HTML DOM implementations and pre-existing
scriptable web browsers.

The result of this is that we have a consistent, reliable and cross
browser (one-code fits-all (at least all that are capable of doing the
dynamic manipulation in the first place)) formulation that will
facilitate the dynamic manipulation of OPTION elements under a SELECT
element, and we have 'more modern' alternatives that bring avoidable
issues with them. If some approach is to be recommended then it seems to
me more sensible to be recommending the consistent, reliable and
cross-browser approach that avoids the issues.

Richard.



Reply With Quote
  #4  
Old   
Stanimir Stamenkov
 
Posts: n/a

Default Re: Writing Arrays To <select> Tag - 06-21-2008 , 02:03 PM



Sat, 21 Jun 2008 07:51:39 -0700 (PDT), /Bart Van der Donck/:
Quote:
Stanimir Stamenkov wrote:

I've not found references to the Option object in the "Gecko DOM
Reference" [2] and the MSDN Library [3] - have I missed them?

Yes.
Could you be so kind and provide them for me? Thanks.

--
Stanimir


Reply With Quote
  #5  
Old   
Bart Van der Donck
 
Posts: n/a

Default Re: Writing Arrays To <select> Tag - 06-22-2008 , 02:07 AM



Stanimir Stamenkov wrote:

Quote:
Sat, 21 Jun 2008 07:51:39 -0700 (PDT), /Bart Van der Donck/:

Stanimir Stamenkov wrote:

I've not found references to the Option object in the "Gecko DOM
Reference" [2] and the MSDN Library [3] - have I missed them?

Yes.

Could you be so kind and provide them for me? *Thanks.
http://msdn.microsoft.com/en-us/libr...77(VS.85).aspx
http://devedge-temp.mozilla.org/libr...ce/option.html

--
Bart


Reply With Quote
  #6  
Old   
Stanimir Stamenkov
 
Posts: n/a

Default Re: Writing Arrays To <select> Tag - 06-22-2008 , 02:55 AM



Sun, 22 Jun 2008 00:07:55 -0700 (PDT), /Bart Van der Donck/:

Thanks. Perhaps I should have stated it more clear earlier. I was
interested where the |Option()| constructor was documented. While
the MSDN resource doesn't mention it, the older JavaScript 1.3
Reference has it. I was puzzled why the newer documentation doesn't
have it, but as Richard Cornford explained in another reply it is
pretty much because "... manufacturer documentation tends to stress
how its authors think things should be done in their own products...".

--
Stanimir


Reply With Quote
  #7  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Writing Arrays To <select> Tag - 06-23-2008 , 01:03 PM



Bart Van der Donck wrote:
Quote:
Stanimir Stamenkov wrote:
Sat, 21 Jun 2008 05:26:33 -0700 (PDT), /Bart Van der Donck/:

Info about the 'Option'-object:
http://www.javascriptkit.com/jsref/s...shtml#section2
I've always wondered how standard (official or not) is the Option
object?

The Option-object is one of the eldest around and was already
supported in the first j(ava)script versions.
Evidently, while `Option' objects have been around since JavaScript 1.0,
their constructor was not available before JavaScript 1.1. The unfortunate
mix between the JavaScript core language and the Netscape Navigator DOM has
been resolved as of JavaScript 1.4. Since JavaScript 1.5 this feature and
other host objects are part of the Gecko DOM instead. (The Gecko DOM
Reference at that, is incomplete. Since it is a public Wiki since quite a
while, it can easily be made complete.)

Evidently as well, the object has never been part of JScript. However, it
is available at least since MSHTML 4.0.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.