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
4 Answers
+ 5
Create an "enchanted/forEach loop"...
+ 4
use document.getElementsByTagName("td")
this would give an array of all <td> elements.
+ 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!
+ 1
thx again!