...

View Full Version : Dynamic element adding not working in IE



mglowacki
05-08-2006, 08:24 AM
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("main:outcomeLangTableTag");
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("main:outcomeLangTableTag");
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('main:odd' + i + 'NameText' + formNumber).value;

td.appendChild(input);
tr.appendChild(td);
}
i++;
if(document.getElementById("main:odd" + 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

Kravvitz
05-08-2006, 09:21 AM
You probably need to append the <tr> to the <tbody> instead of directly to the <table>.

var langTable = document.getElementById("main:outcomeLangTableTag");
if(langTable.getElementsByTagName('tbody').length) {
langTable = langTable.getElementsByTagName('tbody')[0];
}

mglowacki
05-08-2006, 11:04 AM
thanks a lot, that has solved problem in both cases! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum