Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. $(document).ready(function () {
  2. $("input").each(function () {
  3. $(this).keyup(function () {
  4. newSum.call(this);
  5.  
  6.  
  7. });
  8. });
  9. });
  10.  
  11. function newSum() {
  12. var sum = 0;
  13. var thisRow = $(this).closest('tr');
  14.  
  15. var total = 0;
  16.  
  17. //iterate through each input and add to sum
  18. $(thisRow).find("td:not(.total) input").each(function () {
  19.  
  20. sum += parseInt(this.value);
  21. });
  22. //change value of total
  23. $(thisRow).find(".total").html(sum);
  24.  
  25.  
  26. // the grand total
  27. $('.total').each(function () {
  28. total += parseInt($(this).html());
  29. });
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement