javascript - how to get the text from an editable <td> from user input? -


i trying make game here, , i'm still @ 10% of game far. called "sos" familiar? tic tac toe not "x" & "o" "s" , "o" in 5x5, , ill using javascript. have editable td's

<table id="mytable" border="1" style="border-collapse: collapse; width:30%;" cellpadding="8">                     <!-- 1st row -->                     <tr>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                     </tr>                     <!-- 2nd row -->                     <tr>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                     </tr>                     <!-- 3rd row -->                     <tr>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                     </tr>                     <!-- 4th row -->                     <tr>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                     </tr>                     <!-- 5th row -->                     <tr>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                         <td contenteditable="true"></td>                     </tr>                  </table> 

if input text inside td how can campare other td? because score in game have form word sos vertically, diagonally , horizontally. please help:) javascripters:)

example: consider td's. 1st player inputs "s". second player inputs "0". 1st player again inputs "s". that's score player 1.  [s][o][s][ ][ ] [ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ] 

use data-x & data-y attributes on each td, like

<td data-x="0" data-y="0"> x/o </td> <td data-x="0" data-y="1"> x/o </td> ... ... <td data-x="4" data-y="4"> x/o </td> 

now, can access value @ given & j

$('td[data-x="' + + '"][data-y="' + j + '"]').text() 

and don't think there need use contenteditable=true

$ - jquery

if you're not using jquery or using plain javascript let's below:

<td id="x0y0"> x/o </td> <td id="x0y1"> x/o </td> ... ...     <td id="x4y4"> x/o </td> 

then can access value @ & j as

document.getelementbyid('x'+i+'y'+j).value 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -