I need to create a times table using javascript. The user needs to input a number in a text field and when the button his hit it generates a times table into an HTML table. In column 1 it should display the number that was entered into the text field, column 2 should display the loop 1 to 10, and column 3 should display the answer.
I know I need to use onclick, .innerHTML, and getElementById() but I am unsure how to get the results into the table. Please help! ! ! ! !
Presuming you already have your math worked out...
as you cycle through each "times" (x1, x2, x3, ...), you set the innerHTML of each table cell to the value.
e.g.
if "i" is the counter in your loop and "num" is what you are multiplying by, and each cell in your table has an id such as "ans1", "ans2", etc.:
Code:
ans = num * i
document.getElementById('ans' + i).innerHTML = ans
Bookmarks