View Full Version : How to create a table in javascript

07-18-2008, 03:00 AM
i want to know how to create a table in javascript without arrays, well i do have for loop and i cant able to put that loop in my table. so please help me out guys... here is my for loop
func1 = window.prompt('Enter a number:','Enter a number');
document.write( + func1 + " : ");

for ( var i = 1; i<=func1; ++i)
if (func1<=5)
document.writeln( "<tr><td>" + func1 +
"</td><td>" + func1 +
"</td></tr>" );
else if(func1>=5&&func1<=10)
else if(func1>=10&&func1<=20)
else if(func1>20)
document.write("Please enter a correct number")

Thank you for your time

07-18-2008, 04:24 AM
I think you would be much better off using the appendChild method to add TR and TD elements to your table with JavaScript. Much cleaner than injecting markup.

Hope that helps!

07-18-2008, 05:45 AM
i dont how to use it appendchild method in my for loop.. i want output lok like below:
Number | Items
1: | &#37;
2: | ##
3: | ***
4: | $$$$

07-18-2008, 08:01 AM
Is this for an assignment? Also how are the symbols generated? Does each symbol increase by 1 each time i is increased?