Skip to content

Instantly share code, notes, and snippets.

@sanjaykrishnan
Created January 17, 2019 13:27
Show Gist options
  • Save sanjaykrishnan/a36d0698299f5e9dfe50d30fc60e4361 to your computer and use it in GitHub Desktop.
Save sanjaykrishnan/a36d0698299f5e9dfe50d30fc60e4361 to your computer and use it in GitHub Desktop.
Sum of 2 fields using jquery
$(document).ready(function() {
$(".expenses").on('keyup change', calculateSum);
});
function calculateSum() {
var $input = $(this);
var $row = $input.closest('tr');
var sum = 0;
$row.find(".expenses").each(function() {
sum += parseFloat(this.value) || 0;
});
$row.find(".expenses_sum").val(sum.toFixed(2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment