How to append rows and cell to an HTML table with JavaScript -



How to append rows and cell to an HTML table with JavaScript -

i need help trying dynamically create html table using javascript.

here html

<table id="table"> <tr> <th>record:</th> <th>employee name:</th> <th>amount:</th> </tr> </table>

i want populate table array dynamically using java script. far, here have...

for(var i=0;i<info.length;i++){ var tr=document.createelement('tr'); for(var j=0;j<1;j++){ var td=document.createelement('td'); td.appendchild(document.createtextnode(i)); tr.appendchild(td); td=document.createelement('td'); td.appendchild(document.createtextnode(info[i])); tr.appendchild(td); td=document.createelement('td'); td.appendchild(document.createtextnode(hours[i])); tr.appendchild(td); } tbdy.appendchild(tr); } tbl.appendchild(tbdy); body.appendchild(tbl);

it not working... help?

i able accomplish using @zmf's link

table = document.getelementbyid('table') for(var i=0;i<info.length-1;i++){ var record = i+1; var row = table.insertrow(1); var cell0 = row.insertcell(0); var cell1 = row.insertcell(1); var cell2 = row.insertcell(2); cell0.innerhtml = record; cell1.innerhtml = info[i]; cell2.innerhtml = hours[i]; } }

javascript html table

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -