0

how do i create a table in javascript and read/change values in it?

i wanna use a similar code to what i have in c++ for solving a sudoku and to create it in javascript with a bit more friendly user interface since its hard to give an input for a sudoku in the sololearn app in c++ but should be more than possible in javascript (and would be a good exercise for me :) ). so i thought i need to create a 9x9 table and to read values from it...... but i cant seem to find out how to do it...... do i give an id to the entire table and read from it? or give an id for each row/cell? do i have to define the entire (9x9) table in html first (give default values at first or can i have an empty 9x9 table at the start)? or maybe there is a more efficient way to do it without a table? any help would be appreciated

19th Dec 2016, 6:13 PM
Ethan
Ethan - avatar
4 Answers
+ 5
Create an "enchanted/forEach loop"...
20th Dec 2016, 1:05 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
use document.getElementsByTagName("td") this would give an array of all <td> elements.
19th Dec 2016, 7:30 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
edit : in order to read from it i need to use arr[1].innerHTML? (tried to play a bit with it) and how can i update my table using this array after i changed it? (or how do i use it to print a new table?) edit2: i think i managed to make it work - thx for the help!
19th Dec 2016, 9:46 PM
Ethan
Ethan - avatar
+ 1
thx again!
20th Dec 2016, 7:03 PM
Ethan
Ethan - avatar