insertRow madness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hal Burgiss

    insertRow madness

    Hi, and help for a novice trying to get some data dynamically into
    tables. I did a small proof of concept page which works fine in IE6 and
    Mozilla. Using code such as this:

    tbody = document.getEle mentById('tb');
    thead = document.getEle mentById('heade r');

    tr = thead.insertRow (-1);
    td = document.create Element('th');
    tr.appendChild( td);

    /* start building data here */

    [...]

    All is well. I paste essentially the same code with subsequent
    modifications below this point into a more complex page and it breaks on
    IE6 with a 'null is null and not an object' error, regardless of how I
    play with it. It breaks at the insertRow statement. I've tried going to
    createElement in lieu of insertRow and it breaks in exactly the same
    place. No matter what I change. I've tried inserting into the table
    itself, thead, and tbody. All get a null object. And yet the original
    page works fine, with nearly identical code! Ouch, my brain hurts.

    The test pages are:

    http://burgiss.net/work/table.html (works fine)
    http://burgiss.net/work/pricelist.html (breaks)

    Any help is appreciated.

    --
    Hal Burgiss

  • RobG

    #2
    Re: insertRow madness

    Hal Burgiss wrote:[color=blue]
    > Hi, and help for a novice trying to get some data dynamically into
    > tables. I did a small proof of concept page which works fine in IE6 and
    > Mozilla. Using code such as this:
    >
    > tbody = document.getEle mentById('tb');
    > thead = document.getEle mentById('heade r');
    >
    > tr = thead.insertRow (-1);
    > td = document.create Element('th');
    > tr.appendChild( td);
    >
    > /* start building data here */
    >
    > [...]
    >
    > All is well. I paste essentially the same code with subsequent
    > modifications below this point into a more complex page and it breaks on
    > IE6 with a 'null is null and not an object' error, regardless of how I
    > play with it. It breaks at the insertRow statement. I've tried going to
    > createElement in lieu of insertRow and it breaks in exactly the same
    > place. No matter what I change. I've tried inserting into the table
    > itself, thead, and tbody. All get a null object. And yet the original
    > page works fine, with nearly identical code! Ouch, my brain hurts.
    >
    > The test pages are:
    >
    > http://burgiss.net/work/table.html (works fine)
    > http://burgiss.net/work/pricelist.html (breaks)
    >
    > Any help is appreciated.
    >[/color]

    Most probably because you have already created thead as a global
    variable in drawTable() before makeTable() is called.

    Make it local in drawTable() and see what happens.



    --
    Rob

    Comment

    • Hal Burgiss

      #3
      Re: insertRow madness

      On Mon, 09 Jan 2006 04:14:09 GMT, RobG <rgqld@iinet.ne t.au> wrote:
      [color=blue][color=green]
      >> Any help is appreciated.[/color][/color]
      [color=blue]
      > Most probably because you have already created thead as a global
      > variable in drawTable() before makeTable() is called.[/color]

      Wow, thanks. Looked at it for two hours but did not see that.
      [color=blue]
      > Make it local in drawTable() and see what happens.[/color]

      Sadly, making it a local has not helped yet. I even took out
      drawTable() completely and get that error just with makeTable().

      Thanks for the help!!

      --
      Hal Burgiss

      Comment

      • RobG

        #4
        Re: insertRow madness

        Hal Burgiss wrote:[color=blue]
        > On Mon, 09 Jan 2006 04:14:09 GMT, RobG <rgqld@iinet.ne t.au> wrote:
        >
        >[color=green][color=darkred]
        >>>Any help is appreciated.[/color][/color]
        >
        >[color=green]
        >>Most probably because you have already created thead as a global
        >>variable in drawTable() before makeTable() is called.[/color]
        >
        >
        > Wow, thanks. Looked at it for two hours but did not see that.
        >
        >[color=green]
        >>Make it local in drawTable() and see what happens.[/color]
        >
        >
        > Sadly, making it a local has not helped yet. I even took out
        > drawTable() completely and get that error just with makeTable().[/color]

        Ok, cop this. Comment out the line:

        document.getEle mentById('title ').innerHTML = my_title;


        and see what happens... :-x



        --
        Rob

        Comment

        • RobG

          #5
          Re: insertRow madness

          RobG wrote:
          [...]
          [color=blue]
          >
          > Ok, cop this. Comment out the line:
          >
          > document.getEle mentById('title ').innerHTML = my_title;
          >
          >
          > and see what happens... :-x
          >[/color]

          From the MSDN innerHTML reference:

          "The property is read/write for all objects except the following, for
          which it is read-only: COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE,
          TBODY, TFOOT, THEAD, TITLE, TR. The property has no default value.

          ...

          "You can change the value of the title element using the
          document.title property."

          <URL:http://msdn.microsoft. com/library/default.asp?url =/workshop/author/dhtml/reference/dhtml_reference _entry.asp>



          Somewhat bizarre side-effect, eh? ;-p



          --
          Rob

          Comment

          • Hal Burgiss

            #6
            Re: insertRow madness

            On Mon, 09 Jan 2006 05:18:21 GMT, RobG <rgqld@iinet.ne t.au> wrote:[color=blue]
            >
            > Ok, cop this. Comment out the line:
            >
            > document.getEle mentById('title ').innerHTML = my_title;
            >
            >
            > and see what happens... :-x[/color]

            Hey, wow that was it!!! Amazing. Mucho gracias! I feel a tremendous
            weight has been lifted :0

            --
            Hal Burgiss

            Comment

            • Hal Burgiss

              #7
              Re: insertRow madness

              On Mon, 09 Jan 2006 05:24:28 GMT, RobG <rgqld@iinet.ne t.au> wrote:[color=blue]
              >
              > "You can change the value of the title element using the
              > document.title property."
              >
              > Somewhat bizarre side-effect, eh? ;-p[/color]

              Amen. Now just how did you figure that out?

              --
              Hal Burgiss

              Comment

              • Hal Burgiss

                #8
                Re: insertRow madness

                On 9 Jan 2006 06:49:52 -0500, Hal Burgiss <hal@burgiss.ne t> wrote:[color=blue]
                >
                > Hey, wow that was it!!! Amazing. Mucho gracias! I feel a tremendous
                > weight has been lifted :0[/color]

                Even stranger (at least to me), "title" was the id of an h2 element.
                Chaning the id to "foo" has the same effect. Wierd. Thanks again though.

                --
                Hal Burgiss

                Comment

                • RobG

                  #9
                  Re: insertRow madness

                  Hal Burgiss wrote:[color=blue]
                  > On Mon, 09 Jan 2006 05:24:28 GMT, RobG <rgqld@iinet.ne t.au> wrote:
                  >[color=green]
                  >> "You can change the value of the title element using the
                  >> document.title property."
                  >>
                  >>Somewhat bizarre side-effect, eh? ;-p[/color]
                  >
                  >
                  > Amen. Now just how did you figure that out?
                  >[/color]

                  thead was an object, but totally bereft of properties. I kept
                  checking to see when it finally had an ID property.

                  Remove slabs of stuff until properties appear, then add stuff back
                  slowly until they're gone again. First I removed all the lines of
                  makeTable() after the offending line, then the content of the init()
                  function which gave a clue - fortunately there were only about 6 lines!

                  No wonder prototyping/RAD is the only way to do web applications -
                  write a line of code, test everything. Write another line of code,
                  test everything...


                  --
                  Rob

                  Comment

                  Working...