jquery Production Mall Shopping cart auto Calculate amount Form

Source: Internet
Author: User

Very practical jquery Production Mall shopping cart automatically calculate the amount of form code, you can calculate a number of items of the total price.

function IsNumeric (stext) {var validchars = "0123456789.";
   var isnumber=true;
  
   var Char; 
      for (i = 0; i < stext.length && Isnumber = = true; i++) {Char = Stext.charat (i);
         if (Validchars.indexof (Char) = =-1) {isnumber = false;
    
} return isnumber;
};
    function Calcprodsubtotal () {var prodsubtotal = 0;
         
        $ (". Row-total-input"). each (the function () {var valstring = $ (this). Val () 0;
                     
    Prodsubtotal + + parseint (valstring);
         
    });
$ ("#product-subtotal"). Val (prodsubtotal);
};
    function Calctotalpallets () {var totalpallets = 0;
     
        $ (". Num-pallets-input"). each (the function () {var thisvalue = $ (this). Val ();
         
        if ((IsNumeric (Thisvalue)) && (Thisvalue!= ')) {totalpallets + = parseint (Thisvalue);
     
    };
     
    }); $ ("#total-pallets-input"). Val (TotalpAllets);
};
    function Calcshippingtotal () {var totalpallets = $ ("#total-pallets-input"). Val () 0;
    var shippingrate = $ ("#shipping-rate"). Text () 0;
     
    var shippingtotal = totalpallets * shippingrate;
$ ("#shipping-subtotal"). Val (shippingtotal);
};
    function Calcordertotal () {var orderTotal = 0;
    var productsubtotal = $ ("#product-subtotal"). Val () 0;
         
    var shippingsubtotal = $ ("#shipping-subtotal"). Val () 0;
    var orderTotal = parseint (productsubtotal) + parseint (shippingsubtotal);
     
    var ordertotalnice = "$" + orderTotal;
         
$ ("#order-total"). Val (Ordertotalnice);
};
     
        $ (function () {$ ('. Num-pallets-input '). blur (function () {var $this = $ (this);
        var numpallets = $this. val (); var multiplier = $this. Parent (). Parent (). Find ("Td.price-per-pall
         
        ET span "). text (); if ((IsNumeric (numpallets)) &&amP (Numpallets!= '))
             
            {var rowtotal = numpallets * multiplier; $this. CSS ("Background-color", "White"). Parent (). Parent (). Find ("Td.row-t                    
             
        Otal input "). Val (rowtotal); 
                         
        else {$this. css ("Background-color", "#ffdcdc");
         
        };
        Calcprodsubtotal ();
        Calctotalpallets ();
        Calcshippingtotal ();
     
    Calcordertotal ();
}); });


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.