473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

IE vs. DOM

The following works fine in Mozilla:
var makeSelect = function (firstOption, lastOption, thisOption,
thisList)
{
var select = document.createElement ("select");
for (var i = firstOption; i <= lastOption; ++i)
{
var option = document.createElement ("option");
option.value = i;
if (thisList)
{
option.appendChild (document.createTextNode (thisList[i]));
}
else
{
option.appendChild (document.createTextNode (i));
}
if (i == thisOption)
{
option.selected = 1;
option.style.fontWeight = "bold";
}
select.add (option, null);
}
return select;
};

However, IE 6 complains about the select.add statement. The MSDN
documentation on select spouts some sort of blather about using
select.options.add, but that doesn't work either. I notice that IE
defines the add method to take an element and an index rather than two
elements, thus violating the DOM standard.

Any ideas?
Jul 20 '05 #1
8 7106


Joe Kelsey wrote:
The following works fine in Mozilla:
var makeSelect = function (firstOption, lastOption, thisOption,
thisList)
{
var select = document.createElement ("select");
for (var i = firstOption; i <= lastOption; ++i)
{
var option = document.createElement ("option");
option.value = i;
if (thisList)
{
option.appendChild (document.createTextNode (thisList[i]));
}
else
{
option.appendChild (document.createTextNode (i));
}
if (i == thisOption)
{
option.selected = 1;
option.style.fontWeight = "bold";
}
select.add (option, null);
}
return select;
};

However, IE 6 complains about the select.add statement. The MSDN
documentation on select spouts some sort of blather about using
select.options.add, but that doesn't work either. I notice that IE
defines the add method to take an element and an index rather than two
elements, thus violating the DOM standard.

Any ideas?


IE4 already implemented
select.add(option, index)
and whenever there is difference between IE's DOM and the W3C DOM then
so far IE sticks with the IE DOM

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
On 19 Aug 2003 08:32:21 -0700, jo****@zircon.seattle.wa.us (Joe
Kelsey) wrote:
The following works fine in Mozilla:
[SELECT...]
Any ideas?


Use DOM 0, it has the advantage that it works...

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #3
"Joe Kelsey" <jo****@zircon.seattle.wa.us> wrote in message
news:15**************************@posting.google.c om...
The following works fine in Mozilla:
var makeSelect = function (firstOption, lastOption, thisOption,
thisList)
{
var select = document.createElement ("select");
for (var i = firstOption; i <= lastOption; ++i)
{
var option = document.createElement ("option"); <snip> option.selected = 1;
The 'selected' property of an option element is boolean so it probably
should be being set to true (in this case) or false, for clarity, to
avoid the type-conversion and possible implementation errors.

<snip> }
select.add (option, null);
}
return select;
};

However, IE 6 complains about the select.add statement. The
MSDN documentation on select spouts some sort of blather about
using select.options.add, but that doesn't work either. I
notice that IE defines the add method to take an element and
an index rather than two elements, thus violating the DOM
standard. Any ideas?


By "any ideas" I assume you mean 'what will work?'.

IE also does not work with:-

select.appendChild(options);

However:-

select.options[select.options.length] = option;

-does work on IE and Mozilla/Gecko, Opera 7 and probably other DOM
browsers (as it is essentially the way that options were added before
the standards existed so it is supported for back-compatibility).

Richard.
Jul 20 '05 #4
Just as a side note, this version works in both IE and Moz:

var makeSelect = function (firstOption, lastOption, thisOption,
thisList)
{
var select = document.createElement ("select");
var option;

for (var i = firstOption; i <= lastOption; ++i)
{
option = document.createElement ("option");
// Not only does IE define the add method incorrectly,
// it also requires that you add the option to the select
// options collection *before* you can do anything else to it.
if (document.all)
{
// So much for DOM compliance in IE...
select.add (option);
}
else
{
select.add (option, null);
}
option.value = i;
if (thisList)
{
option.appendChild (document.createTextNode (thisList[i]));
}
else
{
option.appendChild (document.createTextNode (i));
}
if (i == thisOption)
{
option.selected = true;
option.style.fontWeight = "bold";
}
}
return select;
};

So, in order to do DOM 1 operations in IE, you have to know about the
incorrectly-implemented functions, read between the lines of
badly-written MSDN articles and follow the folklore documented in
various places like this newsgroup FAQ.

I suppose if I had started writing javascript a few years ago, I might
know some of these idiosyncracies. Since I just started using
javascript, I find it difficuly to go from the standard documents to
implementation without tripping over all of these cracks in the
implementations.

Anyway, the makeSelect function now works in both IE and Moz, the only
browsers I currently need to support for this internal application.
If anyone has any insight into other browser limitations, it might be
interesting, or not. Many articles seem to just fly past this group.

/Joe
Jul 20 '05 #5
"Joe Kelsey" <jo****@zircon.seattle.wa.us> wrote in message
news:15**************************@posting.google.c om...
<snip>
if (document.all)
{
// So much for DOM compliance in IE...
select.add (option);
}
else
{
select.add (option, null); <snip>If anyone has any insight into other browser limitations,
it might be interesting, or not. Many articles seem to
just fly past this group.


Your - if(document.all) - test is OK on Mozilla because it has no
document.all collection but other DOM standards compliant browsers do
(Opera 7, IceBrowser 5 and probably others). That would leave those
browsers attempting to use the select.add function in an IE style when
there is every chance that they actually implement the DOM standard
version.

It is a common cross browser scripting error to test one feature of a
browser and then make assumptions about other features based on the
result of that test.

Richard.
Jul 20 '05 #6
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<bi*******************@news.demon.co.uk>...
"Joe Kelsey" <jo****@zircon.seattle.wa.us> wrote in message
news:15**************************@posting.google.c om...
<snip>
if (document.all)
{
// So much for DOM compliance in IE...
select.add (option);
}
else
{
select.add (option, null);

<snip>
If anyone has any insight into other browser limitations,
it might be interesting, or not. Many articles seem to
just fly past this group.


Your - if(document.all) - test is OK on Mozilla because it has no
document.all collection but other DOM standards compliant browsers do
(Opera 7, IceBrowser 5 and probably others). That would leave those
browsers attempting to use the select.add function in an IE style when
there is every chance that they actually implement the DOM standard
version.


So, do you have a suggestion for a technique to detect the
invalid/non-standard implementation of select.add by IE? Aside from
including some sort of enormous class which reliably detects all
browsers and versions. The given document.all test works quickly but
unreliably. Please suggest a test which works quickly and reliably.

If a particular browser wants to emulate all of the non-standard
behavior of IE, then it needs to emulate *all* of the non-standard
behavior. Opera and whatever else who implement the non-sstandard
document.all need to also implement the non-standard select.add in
order to operate reliably as a quirk-for-quirk replacement for IE.

/Joe
Jul 20 '05 #7
jo****@zircon.seattle.wa.us (Joe Kelsey) writes:
So, do you have a suggestion for a technique to detect the
invalid/non-standard implementation of select.add by IE?
Just detect IE. That is very simple using IE conditional comments:

<script type="text/javascript">
var isIE = false;
</script>
<!--[if IE]>
<script type="text/javascript">
isIE = true;
</script>
<[end if]-->

Aside from including some sort of enormous class which reliably
detects all browsers and versions.
You only ever need to detect the browsers that you *know* that you
need to make exceptions for. Build to standards, make exceptions
for those browsers that don't follow standards. Then unknown browsers
will at least get a chance if they are standards compliant.
The given document.all test works quickly but unreliably. Please
suggest a test which works quickly and reliably.
See above. Detects IE 4+ with absolute certainty and is quite fast.
If a particular browser wants to emulate all of the non-standard
behavior of IE, then it needs to emulate *all* of the non-standard
behavior.
Say who? You?

It's not that they *want* to emulate non-standard behavior. It's just
that people want even badly broken pages to be visible and functional.
To get a larger user base, they implement as little non-standard
behavior as necessary to get sufficiently many broken pages to work.
They will never go for complete bug-by-bug compatability, and they
shouldn't.

You shouldn't use the existence of one non-standard functionality
to infer *anything* about another non-standard functionality.

In a perfect world, they wouldn't need any non-standard behavior, and
they would be happy not to have to waste manpower implementing it.
Opera and whatever else who implement the non-sstandard
document.all need to also implement the non-standard select.add in
order to operate reliably as a quirk-for-quirk replacement for IE.


They don't *want* to be as bad as IE. Apparently, sufficiently many
pages use the non-standard select.add, so Opera Software has
implemented it. I.e., they have done as you demand.
Personally, I would let any DOM implementation allow "undefined"
anywhere the specification asks for "null". The specification is
written for strongly typed languages, and uses "null" for an
non-defined object value. Javascript typically uses "undefined" for
non-specified values (e.g., in functions with optional arguments).

Mozilla has chosen not to do this. They don't have to.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<bi*******************@news.demon.co.uk>...
"Joe Kelsey" <jo****@zircon.seattle.wa.us> wrote in message
news:15**************************@posting.google.c om...
<snip>
If a particular browser wants to emulate all of the
non-standard behavior of IE, then it needs to emulate *all*
of the non-standard behavior. Opera and whatever else who
implement the non-sstandard document.all need to also
implement the non-standard select.add in order to operate
reliably as a quirk-for-quirk replacement for IE.


You are asking that all browsers conform to your expectations so that
you can write code based on your assumptions about browsers. That is
unrealistic, and even if the browser manufactures attempted it they
would still fail to match IE bug for bug. They would either not know
about all IE bugs (some will be undocumented) and would inevitably
introduce their own.


I refuse to use emoticons.

If you cannot distinguish "tilting at windmills" from the rest of the
text, then I guess you just have to somehow survive.

/Joe
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.