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 4 of 4
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    only 1 row visible

    Hi, I've got this code fragment for adding new table into outer table. The problem is that table should contain 2 rows, while only one is displayed. When i change var name of second table from tr1 to tr, the second one is displayed, the first not. When I leave like below first one is visble, second not. Can anyone take a quick look?

    table = document.createElement("table");
    tbody = document.createElement("tbody");
    tr = document.createElement("tr");
    td = document.createElement("td");
    font = document.createElement("font");
    font.className = "bet-name";
    font.appendChild(document.createTextNode(betName));
    td.align = "left";
    td.appendChild(font);
    tr.appendChild(td);
    td = document.createElement("td");
    td.onclick = function(){removeBetTable(this)};
    img = document.createElement("img");
    img.src = "./template/images/betslip/x.gif";
    td.appendChild(img);
    tr.appendChild(td);
    tbody.appendChild(tr);

    tr1 = document.createElement("tr");
    td = document.createElement("td");
    td.align = "left";
    td.setAttribute("style","padding-left: 2px");
    font = document.createElement("font");
    font.className = "bet-name";
    font.appendChild(document.createTextNode("Outcome: " + outcomeName));
    td.appendChild(font);
    tr1.appendChild(td);

    td = document.createElement("td");
    td.align = "right";
    td.setAttribute("style","padding-right: 2px");
    font = document.createElement("font");
    font.className = "bet-name";
    font.appendChild(document.createTextNode("Odd: " + outcomeOdd));
    td.appendChild(font);

    hidden = document.createElement("input");
    hidden.type = "hidden";
    hidden.id = "odd" + outcomeId;
    hidden.value = outcomeOdd;
    td.appendChild(hidden);

    tr1.appendChild(td);


    tbody.appendChild(tr1);
    table.appendChild(tbody);

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, some more data. The problem should be here, as generated table node is not inserted into hierarchy (his parent should be td of tr of tbody and isn't):

    function addBet(betName, outcomeName, outcomeOdd, outcomeId) {
    table = document.getElementById("parentTable");
    if(table.getElementsByTagName('tbody').length) {
    tbody = table.getElementsByTagName('tbody')[0];
    }

    tr = document.createElement("tr");
    td = document.createElement("td");
    gameTable = createBetTable(betName,outcomeName, outcomeOdd,outcomeId);
    td.appendChild(gameTable);
    tr.appendChild(td);
    tbody.appendChild(tr);
    }

    that gives error:

    Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy" code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)" location: "http://localhost:8080/xxx/script.js Line: 12"]

    Line 12 is td.appendChild(gameTable); - I see nothing wrong in adding table to td node. Am I wrong. Changing code to:

    td.appendChild(createBetTable(betName,outcomeName, outcomeOdd,outcomeId));

    inserts table but as I mentioned not into proper place in hierarchy.

    any thoughts?

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Unless is absolutely necessary, use local variables, not global variables

    function myFunction(){
    var myvar1 //this is a local variable
    myvar2//this is a global variable
    }

    The problem is that you have the variable td as global. After you have returned from the function createBetTable() the variable was changed by that function, as you have a td there as well, so that now td is another object.

    Use local variables
    var td
    var tr
    .........
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, that solved all my problems.


  •  

    Posting Permissions

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