I decided to see if I can create an online Sudoku game using HTML, JavaScript, CSS and PHP. So far, I've created the grid but I'm stumped as to why when I try to use an alert box to show their input, I'm either getting "undefined" (when I use .value), blank (when I use .innerText) or the HTML object (when I use .innerHTML). Either I'm missing my coffee but I cannot figure out why neither seem to be working.
My intention is when the user clicks on "Evaluate!", each of the hidden fields (1 for each row) will be populated in a comma-separated format. PHP will receive the content and can break it apart using explode(",", $row), allowing each to be compared as separate arrays against each other. But that's for later.
To save time when reading my code, the problematic area seems to be within the initGrid() function as that's where I'm creating the attributes. I should note, I've checked the console log and there are no errors. Also, I'm trying to do all of this using only JavaScript, not jQuery.
Here's a JSFiddle, although for some reason, my alert boxes aren't working in it but they are in my browser (Chrome, same browser I'm using for JSFiddle).
Here is the troublesome initGrid() function:
function initGrid() {
var table = document.getElementById("mainTable").getElementsByTagName("tbody")[0];
var atts = ["a", "b", "c", "d", "e", "f", "g", "h", "i"];
for (var i = 0; i < atts.length; i++) {
var newRow = table.insertRow(i);
for (var j = 0; j < 9; j++) {
var newCell = newRow.insertCell(j);
newCell.innerHTML = document.getElementById("defaultButtons").innerHTML;
newCell.setAttribute("name", atts[i] + j);
newCell.setAttribute("id", atts[i] + j);
newCell.setAttribute("value", "");
newCell.setAttribute("onKeyUp", "appendData(this.id, this)");
}
}
}