...

View Full Version : insertRow innerHTML



crmpicco
08-17-2005, 12:55 PM
for (u=1;u<=counter;u++)
{
row = document.getElementById('demodiv_t').insertRow(-1)
cell = row.insertCell(-1)
cell.innerHTML = "<h6>TEST</h6>"
}



why does this not build only the number fo rows that the loop dictates.
i.e. counter

Kor
08-17-2005, 01:30 PM
what about a DOM1 solution?


var oTab = document.getElementById('demodiv_t');
var oTbo = document.createElement('tbody');
for(var i=0;i<counter;i++){
var oTr = document.createElement('tr');
var oTd = document.createElement('td');
var oH = document.createElement('h6');
oH.appendChild(createTextNode('TEST'));
oTd.appendChild(oH);oTr.appendChild(oTd);oTbo.appendChild(oTr)
}
oTab.appendChild(oTbo)

crmpicco
08-17-2005, 03:13 PM
i build this table in js (innerHTML)


row = document.getElementById('demodiv_t').insertRow()
//alert("a = " + a);
cell = row.insertCell()
cell.innerHTML = headingArr[a].toProperCase()
cell2 = row.insertCell()
cell2.innerHTML = contentArr[a]

but, when i click the link that runs this code it just adds more rows and doesnt replace
the old ones??

crmpicco
08-17-2005, 04:00 PM
function build_rules(contract_id,heading,content,contracts,counter,records)
{
//alert("ENTRE function build_rules");
if(window.onerror)
{
bError = true;
}

// If the table has already been built for another
// CTC ID then empty the table and build new table for new CTC ID
if(tableComplete==true)
{
heading_str = "";
content_str = "";
headingArr = "";
contentArr = "";
//cell.innerHTML = "";
//cell2.innerHTML = "";
tableComplete=false;
//document.getElementById('demodiv_t').value="";
//delete_row = document.getElementById('demodiv_t').deleteRow()
//delete_cell = delete_row.deleteCell()

var t = document.getElementById("demodiv_t");
//alert("t.rows.length = " + t.rows.length);
//no_of_rows = t.rows.length;
//no_of_rows = parseInt(no_of_rows+1);
//alert("no_of_rows = " + no_of_rows);

if(rowsDeleted!=true)
{
for(r=0;r<t.rows.length;r++)
{
//alert("CONTROL r = " + r);
t.deleteRow(r);
rowsDeleted=true;
}
}
a=0;
}

if(tableComplete!=true)
{
heading_str = heading_str + "~" + heading;
content_str = content_str + "~" + content;

contentArr = content_str.split("~");
headingArr = heading_str.split("~");


div = document.getElementById('demodiv')
row = document.getElementById('demodiv_t').insertRow()
//alert("a = " + a);
cell = row.insertCell()
cell.innerHTML = headingArr[a].toProperCase()
cell2 = row.insertCell()
cell2.innerHTML = contentArr[a]

bTableSetup = true;
a=a+1;
}
}

it seems to only delete some rows???



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum