Microsoft Madness while writting Web2 App !!

Discussion in 'HTML' started by JT, Apr 15, 2008.

  1. JT

    JT Guest

    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.
     
    JT, Apr 15, 2008
    #1
    1. Advertising

  2. JT

    Andy Dingley Guest

    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.
    <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.
     
    Andy Dingley, Apr 15, 2008
    #2
    1. Advertising

  3. 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.


    <snip>

    > 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
     
    Jonathan N. Little, Apr 15, 2008
    #3
  4. JT

    Bergamot Guest

    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
     
    Bergamot, Apr 15, 2008
    #4
  5. JT

    Andy Dingley Guest

    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.
     
    Andy Dingley, Apr 15, 2008
    #5
  6. JT

    JT Guest

    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.
    > <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.
     
    JT, Apr 17, 2008
    #6
  7. JT

    JT Guest

    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.
     
    JT, Apr 17, 2008
    #7
  8. JT

    Bergamot Guest

    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
     
    Bergamot, Apr 17, 2008
    #8
  9. 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<tables.length;i++)
    {
    if ((tables.className=='ruler') || (tables.className=='tech'))
    {
    var trs=tables.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';return
    false}
    trs[j].onmouseout=function(){this.className='';return false}
    }
    }
    }
    }
    }
    }
     
    Jeremy J Starcher, Apr 17, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,371
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    581
    SpamProof
    Oct 21, 2003
  3. =?Utf-8?B?RmVuZw==?=
    Replies:
    1
    Views:
    550
    Craig Deelsnyder
    Jun 13, 2005
  4. Marius Horak

    Madness, I call it madness

    Marius Horak, Jun 4, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    160
    Raterus
    Jun 4, 2004
  5. Manuel Serrano

    Hop, a programming language for the Web2.0

    Manuel Serrano, Jun 2, 2006, in forum: Javascript
    Replies:
    0
    Views:
    99
    Manuel Serrano
    Jun 2, 2006
Loading...

Share This Page