Microsoft Madness while writting Web2 App !!

Microsoft Madness while writting Web2 App !!

am 15.04.2008 14:19:40 von JT

arghh.. I am writing a web app for real-time streaming of market data
(equities) and am implementing a quick getElementsById function as
needed; in gecko FF this is a walk with document.evaluate. In IE i am
using document.all (i presume this is the only efficient alternative
for IE, am i correct?)..

Anyway the madness is this:

var _sID = "501"; // some arbitrary ID which exists in the hierarchy.

var result1 = (typeof document.all[_sID]); //result1 = undefined

// However

for (var x in document.all)
{
if(x == _sID ) //this case is eventually hit (i.e equals true at a
given point)
result2 = document.all[x]; // result2 = is also undefined!!!!
}

Now why would IE say that result2 is undefined when that value was
returned in the enumeration.

Some debugging reveals that this problem only occurs with pure
numerical IDs!!! So pre-pending any market code with an arbitrary
string solves the problem!!! Truly i would love to know what the IE
team was thinking when they implemented this collection!!!

Any thoughts on this? Thank you.

Re: Microsoft Madness while writting Web2 App !!

am 15.04.2008 15:00:16 von Andy Dingley

On 15 Apr, 13:19, JT wrote:

> Some debugging reveals that this problem only occurs with pure
> numerical IDs!!!

If it doesn't begin with a letter (not a digit), then it can't be a
well-formed NAME or ID token, thus isn't well-formed to use in an
attribute (such as id) that is declared as being of type ID. If you
validated your HTML, you'd see this.


This rarely causes a problem for the display of HTML, however it does
cause trouble (as you've seen) with getElementById() etc.

Re: Microsoft Madness while writting Web2 App !!

am 15.04.2008 15:06:55 von lws4art

JT wrote:
> arghh.. I am writing a web app for real-time streaming of market data
> (equities) and am implementing a quick getElementsById function as
> needed; in gecko FF this is a walk with document.evaluate. In IE i am
> using document.all (i presume this is the only efficient alternative
> for IE, am i correct?)..
>
> Anyway the madness is this:
>
> var _sID = "501"; // some arbitrary ID which exists in the hierarchy.



> Some debugging reveals that this problem only occurs with pure
> numerical IDs!!! So pre-pending any market code with an arbitrary
> string solves the problem!!! Truly i would love to know what the IE
> team was thinking when they implemented this collection!!!

Your debugging pointed you to your problem, but in this case it not IE's
fault, but the other way around

'ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".").'

http:///www.w3.org/TR/html4/types.html#type-name

"5" is not a letter

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

Re: Microsoft Madness while writting Web2 App !!

am 15.04.2008 15:49:24 von Bergamot

JT wrote:
>
> am implementing a quick getElementsById function

I assume you mean getElementById (singular, not plural)

> In IE i am
> using document.all (i presume this is the only efficient alternative
> for IE, am i correct?)..

getElementById works in IE just fine. Have you tried it?

--
Berg

Re: Microsoft Madness while writting Web2 App !!

am 15.04.2008 18:56:20 von Andy Dingley

On 15 Apr, 14:49, Bergamot wrote:
> JT wrote:
>
> > am implementing a quick getElementsById function
>
> I assume you mean getElementById (singular, not plural)

He wouldn't need to implement that.

Re: Microsoft Madness while writting Web2 App !!

am 17.04.2008 09:11:21 von JT

On Apr 15, 6:00 pm, Andy Dingley wrote:
> On 15 Apr, 13:19, JT wrote:
>
> > Some debugging reveals that this problem only occurs with pure
> > numerical IDs!!!
>
> If it doesn't begin with a letter (not a digit), then it can't be a
> well-formed NAME or ID token, thus isn't well-formed to use in an
> attribute (such as id) that is declared as being of type ID. If you
> validated your HTML, you'd see this.
>
>
> This rarely causes a problem for the display of HTML, however it does
> cause trouble (as you've seen) with getElementById() etc.

OK i didn't realise that it was not good design to use pure numerical
values for ID. Thanks for pointing it out. I guess we seam to start
blaming microsoft for any problems we have, not good.. cheers.

Re: Microsoft Madness while writting Web2 App !!

am 17.04.2008 09:13:04 von JT

On Apr 15, 6:49 pm, Bergamot wrote:
> JT wrote:
>
> > am implementing a quick getElementsById function
>
> I assume you mean getElementById (singular, not plural)
>
> > In IE i am
> > using document.all (i presume this is the only efficient alternative
> > for IE, am i correct?)..
>
> getElementById works in IE just fine. Have you tried it?
>
> --
> Berg

Nope i did mean getElementsById, getElementById only returns one
object irrespective of how many objects with the same ID exist. In
this case i may have the same market data appear in different DIV
elements and this just want to return an array of all Divs with that
ID; something getElementById will not do. cheers.

Re: Microsoft Madness while writting Web2 App !!

am 17.04.2008 09:33:43 von Neredbojias

On 17 Apr 2008, JT wrote:

> On Apr 15, 6:49 pm, Bergamot wrote:
>> JT wrote:
>>
>> > am implementing a quick getElementsById function
>>
>> I assume you mean getElementById (singular, not plural)
>>
>> > In IE i am
>> > using document.all (i presume this is the only efficient
>> > alternative for IE, am i correct?)..
>>
>> getElementById works in IE just fine. Have you tried it?
>>
>> --
>> Berg
>
> Nope i did mean getElementsById, getElementById only returns one
> object irrespective of how many objects with the same ID exist. In
> this case i may have the same market data appear in different DIV
> elements and this just want to return an array of all Divs with that
> ID; something getElementById will not do. cheers.

Say what? There ain't no "getElementsById", bro. Some say there _is_ a
"getElementsByName", but I've never used it so I can't elucidate
eclectically.

--
Neredbojias
http://www.neredbojias.com/
Great sights and sounds

Re: Microsoft Madness while writting Web2 App !!

am 17.04.2008 14:40:49 von Bergamot

Neredbojias wrote:
>
> Say what? There ain't no "getElementsById", bro.

Um, he just explained he's writing his own function to get multiple
elements.

> Some say there _is_ a
> "getElementsByName"

Maybe you mean getElementsByTagName, which does work beautifully.

--
Berg

Re: Microsoft Madness while writting Web2 App !!

am 17.04.2008 21:11:39 von Jeremy J Starcher

On Thu, 17 Apr 2008 00:13:04 -0700, JT wrote:

> Nope i did mean getElementsById, getElementById only returns one object
> irrespective of how many objects with the same ID exist. In this case i
> may have the same market data appear in different DIV elements and this
> just want to return an array of all Divs with that ID; something
> getElementById will not do. cheers.

HTML 4.01 strict requires that element ids be unique within the document,
though most (all?) browsers do not enforce that rule. Hence, there is no
get ElementsByID.

One common way to flag multiple elements is to give them multiple
classes. Then you can cycle through the elements you are after, see if
they belong to a certain class, then do your operations.

Sample code: (I didn't feel like tracking down the URL)

This code finds all tables in my document that have the class
'ruler' or 'tech' and sets up the table rows for mouse-over highlighting.


/*
tableruler()
written by Chris Heilmann for alistapart.
enables a rollover of rows for each table with the classname ...
*/

function tableruler()
{
if (document.getElementById && document.createTextNode)
{
var tables=document.getElementsByTagName('table');
for (var i=0;i {
if ((tables[i].className=='ruler') || (tables[i].className=='tech'))
{
var trs=tables[i].getElementsByTagName('tr');
for(var j=0;j {
if(trs[j].parentNode.nodeName=='TBODY' && trs[j].className=="")
{
trs[j].onmouseover=function(){this.className='ruled';return
false}
trs[j].onmouseout=function(){this.className='';return false}
}
}
}
}
}
}

Re: Microsoft Madness while writting Web2 App !!

am 17.04.2008 22:44:50 von Neredbojias

On 17 Apr 2008, Neredbojias
wrote:

>>> > am implementing a quick getElementsById function
>>>
>>> I assume you mean getElementById (singular, not plural)
>>>
>>> > In IE i am
>>> > using document.all (i presume this is the only efficient
>>> > alternative for IE, am i correct?)..
>>>
>>> getElementById works in IE just fine. Have you tried it?
>>>
>>> --
>>> Berg
>>
>> Nope i did mean getElementsById, getElementById only returns one
>> object irrespective of how many objects with the same ID exist. In
>> this case i may have the same market data appear in different DIV
>> elements and this just want to return an array of all Divs with that
>> ID; something getElementById will not do. cheers.
>
> Say what? There ain't no "getElementsById", bro. Some say there _is_ a
> "getElementsByName", but I've never used it so I can't elucidate
> eclectically.

Well, you may be correct, but "implementing" can have various nuances and a
quick reading of the original post shows no complete function termed
getElementsById(). Furthermore, I _still_ don't really understand the
question because only 1 instance of a particular id is valid in a document.

--
Neredbojias
http://www.neredbojias.com/
Great sights and sounds

Re: Microsoft Madness while writting Web2 App !!

am 17.04.2008 22:52:51 von Neredbojias

On 17 Apr 2008, Bergamot wrote:

> Neredbojias wrote:
>>
>> Say what? There ain't no "getElementsById", bro.
>
> Um, he just explained he's writing his own function to get multiple
> elements.

Well, you may be correct, but "implementing" can have various nuances and a
quick reading of the original post shows no completed function termed
getElementsById(). Furthermore, I _still_ don't really understand the
question because only 1 instance of a particular id is valid in a document.

>> Some say there _is_ a
>> "getElementsByName"
>
> Maybe you mean getElementsByTagName, which does work beautifully.

Actually, I saw in some Google reference a statement that
"getElementsByName" exists. Not saying the author's right, though, and
yes, I was really thinking of "getElementsByTagName".

--
Neredbojias
http://www.neredbojias.com/
Great sights and sounds