Trying to port my sudoku solving algorithm (which now works!) to javascript, and trying to retrieve the initial values from a series of dropdowns on a page. The basic format of the dropdowns is as follows:
<form action="">
<table>
<tr>
<td>
<select id="sudoku00">
<option value=0></option>
<option value=1>1</option>
...
</select>
</td>
...
</tr>
...
</table>
</form>
The javascript I'm using to try to retrieve these to an array is as follows, but doesn't seem to work:
var grid=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]...]
for (var i=0; i<9; i++){
for (var j=0; j<9; j++){
var current=document.getElementById("sudokuCell"+i.string+j.string);
grid[i][j]=current.options[current.selectedIndex].value;
}
}
It ends up setting the first cell to undefined and the rest to 0 when none of the dropdowns are changed from blank, and each entry in the smaller arrays becomes undefined when I change the dropdowns to anything other than blank. Also if any of this is bad form please let me know, I'm still pretty new to javascript.
Edit: here's the whole thing. Sorry about the bad id, was typing from memory and missed that. http://jsfiddle.net/2Me7E/
stringneeding to bestring()and make sure all the select IDs are correct. If you would like i could make you a fiddlei.stringisn't going to do anything unless you define astring()function on the variable. If you're thinking you need to convert the number inito a string like in Java or C#, where you'd useToString(), then you don't have to do that in JS. JS will automatically convert the number if you're concatenating it with a string.