Table within Table not responding to ElementById call

Discussion in 'Javascript' started by Camet, Jul 6, 2006.

  1. Camet

    Camet Guest

    I have a table created with Javascript. When any row after the first
    row is clicked on, that row expands and shows a smaller table inside of
    it.

    /////////Code Start//////////

    /* rownum is the number of the row of the table that was clicked on.
    Since row 0 contains the headings of the table, but the array of
    objects starts at 0, when calling on the object array, rownum is sent
    minus 1. */
    var rownum = this.rowIndex;

    var stuff;

    /* thisTableId is the id of the outer table that was clicked on */
    var x = document.getElementById('thisTableId').rows[rownum].cells;

    tableArray[rownum-1].image = '<img src="dashSign.gif"><\/img>';
    x[0].innerHTML = tableArray[rownum-1].image;

    /* variable stuff will hold the smaller table's information until added
    to the cell of the row */
    stuff = '<b>' + tableArray[rownum-1].name + '<\/b><BR><BR>';
    var nameId = "newTable";

    /* making the first part of the inner table */
    stuff += '<TABLE border=1 width=100% cellSpacing=0 cellPadding=10
    id="'+nameId +'">';

    for (var h = 0; h < statsArray[rownum-1][2]; h++)
    {
    /* setRow contains the code for each row to be added */
    stuff += regionsArray[rownum-1][h].setRow;
    }
    stuff+= '<\/TABLE>';

    /* after all that, add the new table to the cell. */
    x[1].innerHTML=stuff;
    /* the new table shows up on screen inside of the larger table at this
    point */

    /* this alert shows that the new table seems to have the correct id and
    all the rest of the code. */
    alert(x[1].innerHTML);

    /**** BUT from here on, the table cannot seem to be retrieved. This
    code returns null or undefined when tested ****/
    var table = document.getElementById(nameId);
    rows = table.rows;
    var n = rows.length;

    /////////Code Finished//////////

    note that I am only interested in IE for this project. It does not
    need to be platform compatible.

    If someone could help me, it would be great. I don't understand why
    the new table that was created, cannot be reached.

    Thanks, Camet
    Camet, Jul 6, 2006
    #1
    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. Jeff  Fritz

    table not responding in IE

    Jeff Fritz, Oct 21, 2005, in forum: HTML
    Replies:
    9
    Views:
    407
  2. CJM
    Replies:
    2
    Views:
    1,235
  3. CJM

    Responding to LinkButton within a Gridview

    CJM, Jul 6, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    314
  4. inetquestion
    Replies:
    0
    Views:
    153
    inetquestion
    May 6, 2009
  5. Replies:
    6
    Views:
    194
Loading...

Share This Page