$(document).ready(function () { updateCartTotal(); document.getElementById("emptycart").addEventListener("click", emptyCart); }); /* User Manually empty cart */ function emptyCart() { //remove cart session storage object & refresh cart totals if (sessionStorage.getItem('cart')) { sessionStorage.removeItem('cart'); updateCartTotal(); updateCartCount(); //clear message and remove class style } } function updateCartTotal() { //init var total = 0; var price = 0; var items = 0; var prodCount = 0; var productname = ""; var carttable = ""; if (sessionStorage.getItem('cart')) { //get cart data & parse to array var cart = JSON.parse(sessionStorage.getItem('cart')); //get no of items in cart items = cart.length; //loop over cart array for (var i = 0; i < items; i++) { //convert each JSON product in array back into object var x = JSON.parse(cart[i]); //get property value of price; productid = x.productid; price = parseFloat(x.price); productname = x.productname; count = x.count; totalperproduct = price * count; totalperproduct = parseFloat(totalperproduct.toFixed(2)); //add price to total carttable += "