Pain Posted April 19, 2012 Share Posted April 19, 2012 Hello guys. I am building a 'sudoku' game and i want to load a puzzle (which is actually a text string consisting of 81 digits). I have succeeded in loading just one puzzle, however i want to make it possible to load a different puzzle when the user clicks on a button. Also the old puzzle should be removed. Here is my sudoku board: <div class="group"> <div class="cell"><input type="text" name="8_0" onfocus="{onFocusY=8;onFocusZ=0;}"></div> <div class="cell"><input type="text" name="8_1" onfocus="{onFocusY=8;onFocusZ=1;}"></div> <div class="cell"><input type="text" name="8_2" onfocus="{onFocusY=8;onFocusZ=2;}"></div> <div class="cell"><input type="text" name="8_3" onfocus="{onFocusY=8;onFocusZ=3;}"></div> <div class="cell"><input type="text" name="8_4" onfocus="{onFocusY=8;onFocusZ=4;}"></div> <div class="cell"><input type="text" name="8_5" onfocus="{onFocusY=8;onFocusZ=5;}"></div> <div class="cell"><input type="text" name="8_6" onfocus="{onFocusY=8;onFocusZ=6;}"></div> <div class="cell"><input type="text" name="8_7" onfocus="{onFocusY=8;onFocusZ=7;}"></div> <div class="cell"><input type="text" name="8_8" onfocus="{onFocusY=8;onFocusZ=8;}"></div> </div> <textarea id="puzzle">306500090200400851100780060009368500628000349005924100040097002863001005070003408</textarea> Actually there are nine of them, but there's no point in copying them all, they are pretty much the same. To load the puzzle i've used the following javascript: function ReloadingBoard(){ var puzzle = new String(document.getElementById('puzzle').value); var pos; var ch; var cell; var r; var c; pos = 0; for(c=0;c<=8;c++) { for(r=0;r<=8;r++) { cell = GetCellFromRowcolumn(r,c); ch = puzzle.substr(pos,1); switch(ch){ case '0': cell.value = ''; break; default: cell.value = ch; break; } pos++; } } } and function loadingBoard(){ document.onkeyup = KeyPressed; ReloadingBoard(); } So how do i make the board load a different puzzle when i click the button? Any ideas? Thanks:) Link to comment https://forums.phpfreaks.com/topic/261277-loading-sudoku-puzzle/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.