mercredi 25 avril 2018

How to difference in an if clause between an input value or td text content in javascript

Hello and thank you for take your time reading my issue.

I'm trying to set values to a matrix in the loop below:

for(var i=0; i<9; i++){
    for(var j=0;j<9;j++){
        var aux = i.toString().concat(j.toString());
        // If that I want
        var num = document.getElementById(aux).innerText;
        matriz[i][j] = num;
        // else
        var num = document.getElementById(aux).value;
        matriz[i][j] = num;

    }
}

I have this table in HTML (I'm not going to copy all the table):

<table id="tablero">
  <tr>
    <td> <input id="00" type="text" maxlength="1">  </td>
    <td id="01"></td>
    <td id="02"></td>
    <td id="03"></td>
    <td id="04"></td>
    <td> <input id="05" type="text" maxlength="1"></td>
    <td> <input id="06" type="text" maxlength="1"></td>
    <td id="07"></td>
    <td> <input id="08" type="text" maxlength="1"></td>
  </tr>
  <tr>
    <td id="10"></td>
    <td> <input id="11" type="text" maxlength="1"> </td>
    <td> <input id="12" type="text" maxlength="1"> </td>
..

The td's without inputs have default values. So, how can I differentiate them in the previous loop? Thanks in advance

Aucun commentaire:

Enregistrer un commentaire