Created
January 17, 2019 13:27
-
-
Save sanjaykrishnan/a36d0698299f5e9dfe50d30fc60e4361 to your computer and use it in GitHub Desktop.
Sum of 2 fields using jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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