Mozilla, written html and getElementById

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard A. DeVenezia

    Mozilla, written html and getElementById

    Mozilla (1.4 win2k) doesn't like this

    document.write ('<TABLE ID="abc"><TR><T D></TD></TR></TABLE>')
    table = document.getEle mentById ('abc')
    alert (table.rows.len gth)

    I see in JS Console, Error: table has no properties

    The same message that would appear if I tried to get real non-existant id
    table = document.getEle mentById ('abc-doesnotexist')
    alert (table.rows.len gth)

    Any work arounds ( Not in a position to place my own null table in source
    HTML:( ) ?
    Should I skip making 1.4 happy and wait for Moz 1.5+ ?

    --
    Richard A. DeVenezia


  • Richard A. DeVenezia

    #2
    Re: Mozilla, written html and getElementById

    "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> wrote in message
    news:bjmdbv$ko6 28$1@ID-168040.news.uni-berlin.de...[color=blue]
    > Mozilla (1.4 win2k) doesn't like this
    >
    > document.write ('<TABLE ID="abc"><TR><T D></TD></TR></TABLE>')
    > table = document.getEle mentById ('abc')
    > alert (table.rows.len gth)
    >
    > I see in JS Console, Error: table has no properties[/color]


    This happens in a js that is being loaded in the <HEAD> tag
    --
    Richard A. DeVenezia



    Comment

    • Richard Cornford

      #3
      Re: Mozilla, written html and getElementById

      "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> wrote in message
      news:bjmoen$kuj 71$1@ID-168040.news.uni-berlin.de...[color=blue]
      >"Richard A. DeVenezia" <radevenz@ix.ne tcom.com> wrote in message
      >news:bjmdbv$ko 628$1@ID-168040.news.uni-berlin.de...[color=green]
      >> Mozilla (1.4 win2k) doesn't like this
      >>
      >> document.write ('<TABLE ID="abc"><TR><T D></TD></TR></TABLE>')
      >> table = document.getEle mentById ('abc')
      >> alert (table.rows.len gth)
      > >
      >> I see in JS Console, Error: table has no properties[/color]
      >
      >This happens in a js that is being loaded in the <HEAD> tag[/color]

      A table element within the HEAD of a document would be invalid so if the
      function is called within the head it is unrealistic to expect it to
      work. But I would be expect timing problems with this code anyway as
      the browser may not get a chance to fully set up the objects created
      with the document.write statement before it is references. (Indeed I
      recall that at least one browser delays document.write output until the
      completion of the current script block)

      It would probably be safer to use DOM node insertion methods to create
      and insert a valid table structure. Then you would have a reference to
      it prior to inserting it and would not have to use getElementById at all
      (or give the table an ID). Alternatively you would probably have to
      split the code with the document.write inserting the HTML inline and
      another "init" function being called onload (or with a timeout).

      Richard.


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Mozilla, written html and getElementById

        "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> writes:
        [color=blue]
        > "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> wrote in message
        > news:bjmdbv$ko6 28$1@ID-168040.news.uni-berlin.de...[color=green]
        > > Mozilla (1.4 win2k) doesn't like this
        > >
        > > document.write ('<TABLE ID="abc"><TR><T D></TD></TR></TABLE>')
        > > table = document.getEle mentById ('abc')
        > > alert (table.rows.len gth)
        > >
        > > I see in JS Console, Error: table has no properties[/color][/color]

        My guess:
        You use document.write to insert context in the input stream after
        the current script element. It is not parsed until after the script
        tag ends.

        Try ending the script tag after the document.write and start a new
        script tag with the rest of the code.
        [color=blue]
        > This happens in a js that is being loaded in the <HEAD> tag[/color]

        So, you are writing tables into the head tag? That means that
        the head tag must have stopped, so the browser automatically ends
        the head tag and starts the body tag.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Gavino Paolini

          #5
          Re: Mozilla, written html and getElementById

          Il Wed, 10 Sep 2003 11:32:52 +0200, Lasse Reichstein Nielsen ha scritto:
          [color=blue]
          > "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> writes:
          >[color=green]
          >> "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> wrote in message
          >> news:bjmdbv$ko6 28$1@ID-168040.news.uni-berlin.de...[color=darkred]
          >> > Mozilla (1.4 win2k) doesn't like this[/color][/color][/color]
          ....[color=blue]
          > So, you are writing tables into the head tag? That means that the head
          > tag must have stopped, so the browser automatically ends the head tag
          > and starts the body tag.
          >
          > /L[/color]

          Maybe he meant that the script tag containing that portion of code is
          inside the head and not in the body, I'm just supposing.

          gp

          Comment

          Working...