1

In a datatable, I added a textbox column (2nd column) by append:

 var textbox= '<input type="text" class="txtBox">';

But now, I want to get the value of the textbox. I am doing this via:

 var row_index;

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

  function getIncrement() {

    var dtable = $('#table1').DataTable();
    var textvalue = dtable.rows(row_index).cells(1).value; //textbox column is 2nd
    alert(parseFloat(textvalue));

  }

The problem is I am getting a 'NaN' (Not a number) value. If I remove parseFloat, I am getting 'undefined'. Any ideas? Thank you in advance.

P.S. the row_index value in just fine. If I use alert to get its value, I am getting the correct index. Also, I have no problem getting the value of other row values using the index. I only have problem with the "txtbox" column. Thanks

lulutanseco
  • 313
  • 1
  • 8
  • 29
  • Possible duplicate of [Getting value from a dynamically-generated DataTable input](http://stackoverflow.com/questions/28464914/getting-value-from-a-dynamically-generated-datatable-input) – Anil Mar 17 '17 at 12:26
  • Instead of **dtable.rows(row_index).cells(1).value** you have to use DOM traverse find() function with the specified class – Mayank Pandeyz Mar 17 '17 at 12:28

1 Answers1

1

You can store row instead of rowIndex and later find the textbox within it using find(). Once you get the element call val() to get its value.

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

function getIncrement() {
    alert(parseFloat( $(current_row).find(".txtBox").val()));
}
Adil
  • 146,340
  • 25
  • 209
  • 204