Question

I would like to create a table that is entirely generated by Javascript; however I never did that and I searched a lot on the internet and I don't get how its supposed to works! For example I would want a 3 row and 4 columns table that would display when loading the page with information I would choose to put in it.

Was it helpful?

Solution

This is the code that you need...

var arr = new Array(2);// numbers of columns
for (i = 0; i < arr.length; i++) {
    arr[i]=new Array();
}


arr[0] = new Array("a", "b", "c");//first column
arr[1] = new Array(1,2, 3);//second column

document.write('<table border="1">');

for (i = 0; i < arr.length; i++) {
    document.write("<tr>");
    for (j = 0; j < arr[0].length; j++) {
    document.write("<td>"+arr[i][j]+"</td>");
    }
    document.write("</tr>");
}

you choose the imput

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top