Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to create a table in javascript

    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("%");
    document.writeln( "<tr><td>" + func1 +
    "</td><td>" + func1 +
    "</td></tr>" );
    else if(func1>=5&&func1<=10)
    document.write("#");
    else if(func1>=10&&func1<=20)
    document.write("$");
    else if(func1>20)
    document.write("*");
    else
    document.write("Please enter a correct number")
    }

    Thank you for your time

  • #2
    Regular Coder
    Join Date
    Jun 2008
    Location
    SE Wisconsin, US
    Posts
    222
    Thanks
    1
    Thanked 20 Times in 20 Posts
    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!
    Milwaukee Web Designer and SEO Milwaukee Firm specializing in ASP.Net, C#, VB.Net, SQL Server and Access.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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: | $$$$

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Is this for an assignment? Also how are the symbols generated? Does each symbol increase by 1 each time i is increased?
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •