Get values typed into inputs inside datatable

0

I have a datatable and in each line I have 3 inputs (text, datepicker and select) and a button, which will send PHP, to record what was typed or selected in the inputs of that row. What I'm trying to do is grab the information from the line on which I push the button. What I thought of doing is serializing the table and transforming into an array using JQuery; the problem is that it brings information from all the lines of the datatable , but what I need is just the line that I press the button.

I can not get the values by id of the inputs because the datatable is populated automatically by PHP.

Follow the code below:

var table = $('#tableList').DataTable();
$("#tableList").on("click", ".btnReceived", function() {
    var data = JSON.stringify(table.$('input, select').serializeArray());
    console.log(data);
});

Following is the HTML where the button is created:

<a class='btn btn-orange btn-xs btnReceived' href='#' title='Confirmar Recebimento'><span class='glyphicon glyphicon-saved'></span><a/>
    
asked by anonymous 12.09.2017 / 15:43

1 answer

0

Here's an example of how you could do this by checking and storing only those fields that have information.

document.getElementById('enviar').onclick = function(){
  let elemento = document.getElementsByClassName('a')
  
  let arr = []

  for(let i = 0; i < elemento.length; i++){
    if(elemento[i].value == ''){
      
    }else{
      arr.push({
        'valor': elemento[i].value
      })
    }
  }
  console.log(arr)
}
<input type="text" class="a">
  <input type="text" class="a">
  <input type="text" class="a">
  
  <button id="enviar">Enviar</button>
    
12.09.2017 / 16:29