Capture data from a single TR jquery

0

I have a dynamic table and inside I have a td with a dropdown button with several options in (one is save) that would be specifically capture the specific information of that tr and send it by ajax some idea of how to capture only the information of said tr?

    
asked by Monster 23.01.2018 в 18:35
source

1 answer

1

This should help you.

$( "select" ).change(function() {
  if(this.value == "guardar"){
    
    var tr = $(this).closest('tr');
    var nombre1 = tr.find('td').eq(0).text();
    var nombre2 = tr.find('td').eq(1).text();
    
    console.log(nombre1);
    console.log(nombre2);
    
    //envias los datos por ajax
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
  <tr>
    <td>nombre1</td>
    <td>nombre2</td>
    <td>
    </td>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>
      <select>
        <option value="">seleccione algo</option>
        <option value="guardar">Guardar</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>
      <select>
        <option value="">seleccione algo</option>
        <option value="guardar">Guardar</option>
      </select>
    </td>
  </tr>
</table>
    
answered by 23.01.2018 в 18:58