Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- $('.txt' ).live('keyup', function(){
- calculateSum();
- });
- });
- function calculateSum() {
- var sum = 0;
- //iterate through each textboxes and add the values
- $(".txt").each(function() {
- //add only if the value is number
- if(!isNaN(this.value) && this.value.length!=0) {
- sum += parseFloat(this.value);
- }
- });
- //.toFixed() method will roundoff the final sum to 2 decimal places
- $("#sum").html(sum.toFixed(2));
- }
Add Comment
Please, Sign In to add comment