Advertisement
mrbusche

Untitled

Mar 1st, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.84 KB | None | 0 0
  1.     function recalc(){
  2.     $("[id^=total_item]").calc(    // the equation to use for the calculation
  3.     "qty * price",    // define the variables used in the equation, these can be a jQuery object
  4.     {
  5.         qty: $("input[name^=qty_item_]"),
  6.             if ($("[id^=price_item_]").length > 0) {
  7.          price: $("[id^=price_item_]")
  8.             }
  9.     },    // define the formatting callback, the results of the calculation are passed to this function
  10.     function(s){
  11.       // return the number as a dollar amount
  12.       return "$" + s.toFixed(2);
  13.     },    
  14.         // define the finish callback, this runs after the calculation has been complete
  15.     function($this){
  16.       // sum the total of the $("[id^=total_item]") selector
  17.       var sum = $this.sum();
  18.      
  19.       $("#grandTotal").text(        // round the results to 2 digits
  20.       "$" + sum.toFixed(2));
  21.     });
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement