html - How do I populate a table in Javascript by clicking a button using the onClick() function? -
using javascript, want populate numbers in soduku.setstring(); table once user clicks button "easy". how can achieve using onclick() function?
function initialize() { var col, row; (row = 0; row <=8; row++) { (col=0; col <= 8; col++) { var cell = document.getelementbyid('cell_' + col + '_' + row); if (!parseint(cell.innerhtml)) { // cell empty cell.onclick = selectcell; cell.classname = 'tofill'; } } } document.onkeypress = keypress; } function easygame(){ var sudoku.setstring("240057360000008009378000200060041702080000005000005010130000000050003026000812000"); loadpuzzle(sudoku); updateui(); } function updateui(){ initialize(); } <input type="button" value="easy" onclick="easygame()"/> <table align=center id="sudoku" cellspacing=0> <tr> <td id="cell_0_0"></td> <td id="cell_1_0"></td> <td id="cell_2_0"></td> <td id="cell_3_0"></td> <td id="cell_4_0"></td> <td id="cell_5_0"></td> <td id="cell_6_0"></td> <td id="cell_7_0"></td> <td id="cell_8_0"></td> <tr>
for sudoku, why dont use 2d arrays. logically more easier rather using string. far question goes, use jquery fill in table this,
for(var i=0;i<81;i++) { $('table#sudoku td:eq('+i+')').text(sudokustring[i]); }
Comments
Post a Comment