Guest User

Untitled

a guest
Apr 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.                            
  3.             $('.txt' ).live('keyup', function(){
  4.             calculateSum();
  5.             });
  6.         });
  7.  
  8.     function calculateSum() {
  9.  
  10.         var sum = 0;
  11.         //iterate through each textboxes and add the values
  12.         $(".txt").each(function() {
  13.  
  14.             //add only if the value is number
  15.             if(!isNaN(this.value) && this.value.length!=0) {
  16.                 sum += parseFloat(this.value);
  17.             }
  18.  
  19.         });
  20.         //.toFixed() method will roundoff the final sum to 2 decimal places
  21.         $("#sum").html(sum.toFixed(2));
  22.     }
Add Comment
Please, Sign In to add comment