www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help with Multiplication Table?

  1. #1
    Join Date
    Nov 2007
    Posts
    1

    Help with Multiplication Table?

    Hello,

    I was wondering if anyone could help with this javascript code I am trying to write. It is just to make a multiplication table and there isnt really much that matters except that you get 2 inputs and it creates it in table form like this:

    How big do you want your table?
    [ m ] by [ n ]
    Click To create

    And when you create it it opens in a new window and makes a table out of it with whatever two numbers you picked: (6x6 for example)

    x 1 2 3 4 5 6
    1 1 2 3 4 5 6
    2 2 4 6 8 10 12
    3 3 6 9 12 . .
    4 . . . . .
    5
    6

    etc.

    I saw a nother multiplication post on these forums and it was for a single digit and output it in mostly text form so I thought maybe someone could help me with this one.

    Thanks

  2. #2
    Join Date
    May 2007
    Location
    Cleveland, OH
    Posts
    1,403
    You'd have to create a table, and loop through it to create the individual cells.
    PHP Code:
    var table document.createElement("table");
    var 
    tbody document.createElement("tbody"// you need this for IE :(
    for (var 0y.lengthi++) {
      var 
    tr document.createElement("tr");
       
      for (var 
    0x.lengthj++) {
         var 
    td document.createElement("td");

         var 
    val 2*2;
         var 
    txt document.createTextNode(val);
         
    td.appendChild(txt);
         
    tr.appendChild(td);
      }
      
    tbody.appendChild(tr)
    }
    table.appendChild(tbody);

    document.appendChild(table); 
    Don't know if thats 100% correct, but you can see how its done.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles