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

    Dynamic element adding not working in IE

    Hi

    I have such a function which works fine in FireFox but not in IE - it's not adding any elements to the table. Can anyone help?

    function showLangDetails() {
    panel = document.getElementById("mainutcomeLangTableTag");
    if(panel.style.display == "block") {
    panel.style.display = "none";
    return;
    }
    panel.style.display = "block";
    rows = panel.getElementsByTagName('tr');

    var parent;
    for(var i=rows.length-1;i>0;i--) {
    parent = rows[i].parentNode;
    parent.removeChild(rows[i]);
    }


    var langTable = document.getElementById("mainutcomeLangTableTag");
    langCount = document.getElementById('main:languagesCountHidden').value;
    document.body.appendChild(document.createTextNode(langCount));

    var formNumber;
    for(var i=1;i<=3;i++)
    {
    panel = document.getElementById("main:type" + i + "Grid");
    if(panel.style.display == "block") {
    formNumber = i;
    }
    }
    var flag = true;
    var i=1;
    while(flag) {
    tr = document.createElement("tr");
    for(var j=1;j<=langCount;j++) {
    td = document.createElement("td");
    input = document.createElement("input");
    input.setAttribute("type","text");
    input.setAttribute("id","langname" + i + "x" + j);
    input.value = document.getElementById('maindd' + i + 'NameText' + formNumber).value;

    td.appendChild(input);
    tr.appendChild(td);
    }
    i++;
    if(document.getElementById("maindd" + i + "NameText" + formNumber) == undefined) {
    flag = false;
    }
    langTable.appendChild(tr);
    }

    }


    Also I have another one which also should add some tr,td and input elements, but works only in FF too.

    Thanks in advance,
    Michal

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You probably need to append the <tr> to the <tbody> instead of directly to the <table>.
    Code:
    var langTable = document.getElementById("main:outcomeLangTableTag");
    if(langTable.getElementsByTagName('tbody').length) {
      langTable = langTable.getElementsByTagName('tbody')[0];
    }
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot, that has solved problem in both cases!


  •  

    Posting Permissions

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