HighDots Forums  

Microsoft Madness while writting Web2 App !!

alt.html alt.html


Discuss Microsoft Madness while writting Web2 App !! in the alt.html forum.



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

Default Microsoft Madness while writting Web2 App !! - 04-15-2008 , 07:19 AM






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.

Reply With Quote
  #2  
Old   
Andy Dingley
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-15-2008 , 08:00 AM






On 15 Apr, 13:19, JT <jamie.taleyark... (AT) gmail (DOT) com> wrote:

Quote:
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.
<http://www.w3.org/TR/html4/types.html#type-id>

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


Reply With Quote
  #3  
Old   
Jonathan N. Little
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-15-2008 , 08:06 AM



JT wrote:
Quote:
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.
<snip>

Quote:
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


Reply With Quote
  #4  
Old   
Bergamot
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-15-2008 , 08:49 AM



JT wrote:
Quote:
am implementing a quick getElementsById function
I assume you mean getElementById (singular, not plural)

Quote:
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


Reply With Quote
  #5  
Old   
Andy Dingley
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-15-2008 , 11:56 AM



On 15 Apr, 14:49, Bergamot <berga... (AT) visi (DOT) com> wrote:
Quote:
JT wrote:

am implementing a quick getElementsById function

I assume you mean getElementById (singular, not plural)
He wouldn't need to implement that.


Reply With Quote
  #6  
Old   
JT
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-17-2008 , 02:11 AM



On Apr 15, 6:00 pm, Andy Dingley <ding... (AT) codesmiths (DOT) com> wrote:
Quote:
On 15 Apr, 13:19, JT <jamie.taleyark... (AT) gmail (DOT) com> 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.
http://www.w3.org/TR/html4/types.html#type-id

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.


Reply With Quote
  #7  
Old   
JT
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-17-2008 , 02:13 AM



On Apr 15, 6:49 pm, Bergamot <berga... (AT) visi (DOT) com> wrote:
Quote:
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.


Reply With Quote
  #8  
Old   
Neredbojias
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-17-2008 , 02:33 AM



On 17 Apr 2008, JT <jamie.taleyarkhan (AT) gmail (DOT) com> wrote:

Quote:
On Apr 15, 6:49 pm, Bergamot <berga... (AT) visi (DOT) com> 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


Reply With Quote
  #9  
Old   
Bergamot
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-17-2008 , 07:40 AM



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

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

--
Berg


Reply With Quote
  #10  
Old   
Jeremy J Starcher
 
Posts: n/a

Default Re: Microsoft Madness while writting Web2 App !! - 04-17-2008 , 02:11 PM



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

Quote:
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<tables.length;i++)
{
if ((tables[i].className=='ruler') || (tables[i].className=='tech'))
{
var trs=tables[i].getElementsByTagName('tr');
for(var j=0;j<trs.length;j++)
{
if(trs[j].parentNode.nodeName=='TBODY' && trs[j].className=="")
{
trs[j].onmouseover=function(){this.className='ruled';ret urn
false}
trs[j].onmouseout=function(){this.className='';return false}
}
}
}
}
}
}


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.