Browse table with N lines with FOR and find specific values

0

How to move a table with N rows and find the values specific to each DropDownList ?

Example of the table below:

Itriedthecodebelow,butwithoutsuccess.

functionValidarStatusGrid(){vartemp,td;vartable=$("tbPedidos");
        var status = $("#sclStatusGrid");
        temp = document.getElementById('tbPedidos').getElementsByTagName('tr');
        for (var i = 0; i < temp.length + 1; i++) {
            td += temp[i];
        }
    }
    
asked by anonymous 13.04.2018 / 19:05

2 answers

2

To go through the lines you can do this:

$('#tbPedidos> tbody  > tr').each(function() {
   // aqui tem a linha (tr)
   var linha = $(this);
});

However, if you specifically want the selects in the table, you can do this:

$('#tbPedidos select').each(function() {
    // aqui tem o valor da cada select
    var valor = $(this).val();
});
    
13.04.2018 / 19:17
1

I made a foreach of jQuery in the% w of the table, and saved I got the value using td of each element.

  function ValidarStatusGrid() {
        var table = $("#tbPedidos");
        table.find('tbody tr').each(function() {
            var resultado = $(this).find('td select').find('option:selected').val();
            alert(resultado);
        });
    }
    $('#tbPedidos select').on('change', function () {
        ValidarStatusGrid();
    });
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><tableid="tbPedidos">
      <thead>
      <tr>
        <td>Pedido</td>
        <td>Selecione</td>
      </tr>
      </thead>
      <tbody>
        <tr>
          <td>651981</td>
          <td><select><option value="valor selecionado 01">opção 01</option><option value="valor selecionado 02">opção 02</option></select></td>
        </tr>
      </tbody>
    </table>
    
13.04.2018 / 19:28