How to create table in html using for loop

I am trying to create a simple times table in a html document using Javascript. This is my code so far:


    
    
        Table
    
    
    
    
    

I looked through the posted questions, but could not find an answer, possibly because I am a beginner programmer and did not understand most of it.

How to create table in html using for loop

asked Feb 26, 2014 at 12:58

2

Well, first of all you should insert the tr (rows) and td (cells) into a table element... Something like

document.write("");
// your loop here
document.write("
");

There are better ways to do this, though!

answered Feb 26, 2014 at 13:04

How to create table in html using for loop

LucaLuca

1,0501 gold badge14 silver badges24 bronze badges

1

use '+' to concate.




Table





answered Feb 26, 2014 at 13:00

TKVTKV

2,37310 gold badges42 silver badges55 bronze badges







answered Aug 31, 2015 at 18:04

How to create table in html using for loop







answered Aug 31, 2015 at 18:00

How to create table in html using for loop

function year(){ var test = ''; var tr=''; for(var i=0;i<4;i++){ tr += ''; for(var j=0;j<4;j++){ tr += ''; } } tr +=''; test += tr; return document.getElementById('yr').innerHTML = test; } year();

Noy

1,2482 gold badges11 silver badges28 bronze badges

answered Feb 16, 2016 at 11:05

How to create table in html using for loop

vijayvijay

1862 silver badges12 bronze badges

1







<2015-2016>
'+2015+'

answered Oct 13, 2017 at 10:12

How do you create a loop table in HTML?

“using a for loop to create a table javascript” Code Answer.
var table = document. getElementById("myTable");.
for (let i in table. rows) {.
let row = table. rows[i].
//iterate through rows..
//rows would be accessed using the "row" variable assigned in the for loop..
for (let j in row. ... .
let col = row. ... .
//iterate through columns..

How do you create a loop in a table?

var table = document. createElement('table'), tr, td, i; for (i = 0; i < 220; i++) { if (i % 22 == 0) { // every 22nd cell (including the first) tr = table. appendChild(document. createElement('tr')); // add a new row } td = tr.

How do you use a loop in a table?

Algorithm. Step 1: Enter a number to print table at runtime. Step 2: Read that number from keyboard. Step 3: Using for loop print number*I 10 times. // for(i=1; i<=10; i++) Step 4: Print num*I 10 times where i=0 to 10.

Can we use for loop in HTML?

Approach 1: Using the for loop: The HTML elements can be iterated by using the regular JavaScript for loop. The number of elements to be iterated can be found using the length property. The for loop has three parts, initialization, condition expression, and increment/decrement expression.