Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a table to square numbers

Status
Not open for further replies.

Salha915

Instructor
Feb 7, 2001
1
US
I need to write a code that uses a "while" statement to prompt the user for a number and then creates a table with one column 1-to the number they chose and another column of the squares of each number. Ex. 1 1
2 4
3 9

Then I need to write another code that will loop through and change the background color from white to yellow.
All this will be done in HTML.
Help would be greatly appreciated.
 
So you want to creat tables dynamically? use:
var newTable = document.createElement('tagName')
e.g. document.createElement('table');


to actually make the table - so set up a loop to create the right number of cells.

Then what do you mean loop thru and change the bgColor? You can just set the table's bgColor attribute:


newTable.setAttribute('bgColor','yellow')


It does eem like overkill though, I know, when it's easier to just assign values to the attributes! It's just important to give yourself a way of targetting elements - here I am holding the new tbale in a variable - but if you set it's name,ot id attribute, you can use that. "Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top