paul pagente paul pagente - 3 years ago 193
HTML Question

Create a TBODY using Array

I have an array that looks like this.

enter image description here

now here is my code for that

success: function(data) {
data = $.parseJSON(data);
for (i = 0; i < data.length; i++) {

displays it

here is my table

<table id "tblreport" class="mytable" style="width: 900px; margin-right: auto; height: 18px;" border="1">
//Table Headers here
<tbody id = "body">


my question is using that array how can I make it as a data in tbody?

Answer Source

Pretty sure you want this:

for(var i=0,a,tr,l=data.length; i<l; i++){
  a = data[i]; tr = document.createElement('tr');
  for(var n=0,td,c=a.length; n<c; n++){
    td = document.createElement('td'); td.innerHTML = a[n]; tr.appendChild(td);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download