Pregunta

First, I have a Google visualisation dataTable.

After that I create a for loop to get table cell values and put then in input fields:

for (var y = 0, maxrows = data.getNumberOfRows(); y < maxrows; y++) {
    for (var x = 1, maxcols = data.getNumberOfColumns(); x < maxcols; x++) {

      data.setValue(y, x, '<input id="costRedovi" vr="'+ data.getValue(y,0) + '" kol="'+ data.getColumnLabel(x) +'" class="form-control" value="'+data.getValue(y,x)+'">');
    }
} 

Now every value is into table cell into input field. Now I can change those values when table is ready, but how to get those values now because my script produce this HTML code now. Also I need to get value on event .focusout on an input field:

<tr class="google-visualization-table-tr-even google-visualization-table-tr-sel">
   <td class="google-visualization-table-td"><input id="costRedovi" vr="2013-04-01" kol="John Deer n7" class="form-control" value="0"></td>
   <td class="google-visualization-table-td"><input id="costRedovi" vr="2013-04-01" kol="Laza Lazic" class="form-control" value="0"></td>
</tr>

I tried to do this:

new google.visualization.events.addListener(table, 'ready', function () {

    $("#costRedovi").focusout(function() {
        console.log($('#costRedovi').attr('value'));                        
    });

});

The problem is that every input has the same ID now.

¿Fue útil?

Solución

If you were to use a class instead of an ID, that is:

<tr class="google-visualization-table-tr-even google-visualization-table-tr-sel">
  <td class="google-visualization-table-td"><input vr="2013-04-01" kol="John Deer n7" class="form-control costRedovi" value="0"></td>
  <td class="google-visualization-table-td"><input vr="2013-04-01" kol="Laza Lazic" class="form-control costRedovi" value="0"></td>
</tr>

You could then retrieve the unfocused-input like so:

$(".costRedovi").focusout(function() {
  var origval = $(this).attr('value');
  var editedval = $(this).val();

  console.log("before: " + origval + ", after:" + editedval);
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top