Take the cell value of a Javascript table

Asked

Viewed 579 times

0

[Help] I need to enter the node value automatically in the last input text "Gesamt" after entering any value of the first vertical column, inside the input text "Mundlich" and the first horizontal line, inside the input text "Schriftlich". That is.. I need to take the index value of the node that crosses a value between the first line and the first column link: git clone https://github.com/mauro16/tabela.git inserir a descrição da imagem aqui

1 answer

1

See if that helps you: Clickable table

<html>
     <head>
          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
          <script>
               function selecionaCelula(id) {
                    var celula = $('#' + id).text();
                    var linha = $('#' + id.substring(1, id.length)).text();
                    var coluna = $('#' + id.substring(1, 0)).text();  
                    $('#g').val(celula);
                    $('#m').val(linha);
                    $('#s').val(coluna);
               }
          </script>
          <style>
               td {
                  cursor: pointer;
               }
          </style>
     </head>
     <body>
          <input type="text" class="form-control mb-2 mr-sm-2" name="m" id="m" placeholder="Mundlich">
          <input type="text" class="form-control mb-2 mr-sm-2" name="s" id="s" placeholder="Schriftlich">
          <input type="text" class="form-control mb-2 mr-sm-2" name="g" id="g" placeholder="Gesamt">

          <table class="table table-hover table-bordered">
             <thead>
                <tr>
                   <th id="NUM">#</th>
                   <th id="A">A</th>
                   <th id="B">B</th>
                   <th id="C">C</th>
                   <th id="D">D</th>
                   <th id="E">E</th>
                </tr>
             </thead>
             <tbody>
                <tr>
                   <th id="1">1</th>
                   <td id="A1" onclick="selecionaCelula(this.id)">A1</td>
                   <td id="B1" onclick="selecionaCelula(this.id)">B1</td>
                   <td id="C1" onclick="selecionaCelula(this.id)">C1</td>
                   <td id="D1" onclick="selecionaCelula(this.id)">D1</td>
                   <td id="E1" onclick="selecionaCelula(this.id)">E1</td>
                </tr>
                <tr>
                   <th id="2">2</th>
                   <td id="A2" onclick="selecionaCelula(this.id)">A2</td>
                   <td id="B2" onclick="selecionaCelula(this.id)">B2</td>
                   <td id="C2" onclick="selecionaCelula(this.id)">C2</td>
                   <td id="D2" onclick="selecionaCelula(this.id)">D2</td>
                   <td id="E2" onclick="selecionaCelula(this.id)">E2</td>
                </tr>
            </tbody>
        </table>
     </body>
</html>

  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision

  • 1

    @13dev Thank you for the indication.

  • First of all, thank you for your attention, Diego. I edited the question, I think it’s now better explained, I need to get the value of the node after selecting any value from the first row and the first column is put in the last input text "Gesamt" using the keyup Even.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.