dimanche 9 septembre 2018

HTML/Javascript: Im trying to retrieve an especific checkbox value inserted in a table

I need to obtain the value from a matrix cell which is not unique. This model is a simplification of the original model which is a huge matrix and that is why I put enfasis on this: document.getElementById("myTable").rows[0].cells[0].XXXXXX.

Objetive: What property or method should I use in that instruction to obtain the value of a checkbox (true/false) or (1,0).

Thank you!!!!

<!DOCTYPE html>
<html>

<head>
  <style>
    table,
    td {
      border: 1px solid black;
    }
  </style>
</head>

<body>

  <p>Tratando de obtener valores de los checkbox dentro de una tabla.</p>

  <table id="myTable">
    <tr>
      <td id='C1'> <input type='checkbox' checked='checked' </td>
        <td id='C2'> <input type='checkbox' checked='checked' </td>
    </tr>
    <tr>
      <td id='C3'> <input type='checkbox' checked='checked' </td>
        <td id='C4'> <input type='checkbox' checked='checked' </td>
    </tr>
  </table>
  <p id="print1"></p>
  <p id="print2"></p>
  <p id="print3"></p>
  <p id="print4"></p>

  <br>

  <button onclick="myFunction()">Intentarlo</button>

  <script>
    function myFunction() {
      document.getElementById("print1").innerHTML = document.getElementById("myTable").rows[0].cells[0];

    }
  </script>

</body>

</html>




Aucun commentaire:

Enregistrer un commentaire