/* * for adding a quantity to the cart *using jquery * Copyright (c) Janno Palacios * Dual licensed under the MIT and GPL licenses. */ $(document).on("keyup", ".QTY", function () { var productid = $(this).data('id'); // alert(productid); var qty = document.getElementById('QTY'+productid); var originalqty = document.getElementById('ORIGQTY'+productid); var price = document.getElementById('PROPRICE'+productid); var subtot; // alert(qty); if (parseInt(originalqty.value)<=parseInt(qty.value)){ alert("The quantity that you put is greater than the availabe quantity of the product."); document.getElementById('QTY'+productid).value = originalqty.value; subtot = parseFloat(price) * parseFloat(originalqty.value); } else{ subtot = parseFloat(price.value) * parseFloat(qty.value); } subtot = parseFloat(price.value) * parseFloat(qty.value); // alert(subtot.toFixed(2)) // $.ajax({ //create an ajax request to load_page.php // type:"GET", // url: "cart.php?QTY"+productid+"="+ qty + "&subTOT"+productid+"=" + subtot.toFixed(2), // dataType: "text", //expect html to be returned // data:{updateid:productid}, // success: function(data){ // $("#CART").html(data); // // alert(data); // } // }); document.getElementById('TOT'+productid).value = subtot.toFixed(2); document.getElementById('Osubtot'+productid).value = document.getElementById('TOT'+productid).value; var table = document.getElementById('table'); var items = table.getElementsByTagName('output'); var sum = 0; for(var i=0; i