lulutanseco
lulutanseco

Reputation: 423

jquery: access value of a textbox in datatable

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

Upvotes: 1

Views: 3679

Answers (1)

Adil
Adil

Reputation: 148140

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()));
}

Upvotes: 1

Related Questions