1

I want to calculate new value upon keypress in a textbox inside a datatable. However, the textbox inside the datatable is not triggering upon keypress.

$(document).on('mouseover', '#table1 tr', function() {
  rndex = this;
  jindex = this.rowIndex;
});

var dtable = $('#table1').DataTable();
var origval = $('#table1 tr:eq(' + parseInt(rndex) + ') >td:eq(' + 1 + ')').html();
var $textvalue = $(jindex).find(".txtBox");
var newval; 

$textvalue.on('keypress', function(e) {
  if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
    e.stopImmediatePropagation();
    return false;
  }
}).on('keyup change', function(e) {
  newval = parseFloat(origval) + this.value;
  alert(origval);
});

Output

Thank you in advance!

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
lulutanseco
  • 313
  • 1
  • 8
  • 29
  • The contents of a DataTable are dynamically generated, so you need to use a delegated event handler. See the duplicate question for more information – Rory McCrossan Apr 20 '17 at 08:10

0 Answers0