Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question help appending nodes

    Hello, I am trying to create a script that will put the contents of an array into a dynamically generated table 3 columns wide. In this case, a really simple example that will insert the numbers "one" thru "six" (actually 7 in the array, but I don't yet have a case for the final incomplete row). For some reason I can't even get the first cell attached to the first row. Please let me know what I'm doing wrong.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <script type="text/javascript">
    function startup()
    {
      colcount = 0;
      rowcount = 0;
      var List = new Array('one','two','three','four','five','six','seven');
      var Count = 7;
      tabBody=document.getElementsByTagName("TBODY").item(0);
      for (var i = 0; i<Count; i++)
      {
         if (colcount == 0)
         {
           var row=document.createElement("TR");
           rowcount++;
           row.id = rowcount;
         }
         cell = document.createElement("TD");
         textnode=document.createTextNode(List[i]);
         cell.appendChild(textnode);
         document.getElementById(rowcount).appendChild(cell);
         colcount++;
         if (colcount == 3)
         {
           tabBody.appendChild(row);
           colcount = 0;
         }
      }
    }
    </script>
    </head>
    <body onload="startup()">
    <table border='1' id='mytable'>
    <tbody>
    </tbody>
    </table>
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,561 Times in 2,539 Posts
    document.getElementById( "mytable" ).appendChild(cell);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •