This is a take off from the following solved questions (so please don't tag this as duplicate):
I created a dynamic textbox in a datatable. Now, I need to access that value to compute a new value upon keypress. While I find the answers on (Event binding on dynamically created elements?) extremely useful, I am still at lost how to get value of the textbox.
The "keyup change" function is already triggered since I am getting the alert. However, I am getting a 'NaN' (not a number) value. Please help!
this is my code:
var xindex;
var yindex;
$(document).on('mouseover', '#table1 tr', function() {
xindex = this;
yindex = this.rowIndex;
});
var dtable = $('#table1').DataTable();
var origval = $('#table1 tr:eq(' + parseInt(yindex) + ') >td:eq(' + 1 + ')').html();
//this is the original value in which I would like to add the adjustment
var textvalue = $(yindex).find(".txtval");
//upon creating the datatable dynamically, the class of the input textbox is "txtval"
var newval;
$(document).on('keypress', '.textvalue', 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 = origval + this.value;
alert(newval);
});