1

I have created ten separate tables in javascript using HTML tags. I now want to put those tables in a grid format so I thought putting them into another table would work. This code just makes an empty table appear. Any help? Thanks!

 document.getElementById('InstalledApps').innerHTML += '<table id="bigAppsTable" border="1"><td>';

    for (var i = 9; i>-1;i--){  
        document.getElementById('InstalledApps').innerHTML += '<table id="appsTable'+i+'" border="1"><tr></tr>';

        var thirdRow=document.getElementById("appsTable"+i).insertRow(1);
        if (the_data[i]['release'] != null){
        thirdRow.insertCell(-1).innerHTML="<b>Release: ";
        thirdRow.insertCell(-1).innerHTML=the_data[i]['release'];
        }
        var secondRow=document.getElementById("appsTable"+i).insertRow(1);
        secondRow.insertCell(-1).innerHTML="<b>Version: ";
        secondRow.insertCell(-1).innerHTML=the_data[i]['version'];

        var firstRow=document.getElementById("appsTable"+i).insertRow(1);
        firstRow.insertCell(-1).innerHTML="<b>Name:";
        firstRow.insertCell(-1).innerHTML=the_data[i]['name'];

        }
Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
Zach Lucas
  • 1,631
  • 5
  • 15
  • 29

2 Answers2

0

Since you're dynamically creating tables, why not use the DOM API? (ie. not innerHTML)

Here is a good place to get your started: https://developer.mozilla.org/en-US/docs/Web/API/document.createElement

Halcyon
  • 57,230
  • 10
  • 89
  • 128
0

Try like this

var aTable = document.createElement('table');

for (var i = 0, tr, td; i < 9; i++) {
    tr = document.createElement('tr');
    td = document.createElement('td');
    td.appendChild(document.createTextNode("some text"));
    tr.appendChild(td);
    aTable.appendChild(tr);
}

//update with id
document.getElementById('table').appendChild(aTable);
usman allam
  • 274
  • 1
  • 5