0

I have a total of three columns in the table, in the first column I have retrieved the information from the database, in the second column there is an input field where the first column will be added to the information I will give and it will be displayed in the third column.

I have followed the below methods but the results are always coming NaN

$(document).ready(function() {
  $('[name=column_two]').on('change', function(i) {
    if (i == 0) return true;
    var tr = $(this).closest('tr');
    var column_one = parseFloat($('[name=column_one]', tr).text());
    var column_two = parseFloat($('[name=column_two]', tr).text());
    $('[name=column_five]').text(column_one + column_two);
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<td style="border: 1px solid black" name="column_one">
  Column one
</td>
<td style="border: 1px solid black">
  <input type="text" name="column_two" class="form-control">
</td>
<td style="border: 1px solid black" class="" name="column_five"></td>
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
John
  • 91
  • 2
  • 10
  • 1
    What is the output of column_one and column_two in console.log()? – Ballard Apr 22 '22 at 14:46
  • Search a bit and you will find wonderful things like this... https://stackoverflow.com/questions/3811678/add-two-variables-using-jquery I bet this gets you through your problem. –  Apr 22 '22 at 15:58

0 Answers0