First , go here: http://webapps.bcit.ca/A00839579/MDIA3207/Assign4/cart.html
Basically, I would like when someone updates the quantity of an item it’ll update the “Sub-total” in the bottom right. Shouldn’t be too hard, but for some reason I can’t figure it out. And on a side note, if can figure out how I can keep the prices with decimals when the quantity gets updated, that’d be great too. Thanks so much!
Here’s my JavaScript:
var artprice = 28.99;
var artquantity = document.getElementById("artquantity").value;
var arttotal = (artprice * artquantity).toFixed(2) - 0;
var loverprice = 19.95;
var loverquantity = document.getElementById("loverquantity").value;
var lovertotal = (loverprice * loverquantity).toFixed(2) - 0;
var nightprice = 32.00;
var nightquantity = document.getElementById("nightquantity").value;
var nighttotal = (nightprice * nightquantity).toFixed(2) - 0;
function artupdate() {
var subtotal = arttotal + lovertotal + nighttotal;
var artprice = 28.99;
var artquantity = document.getElementById("artquantity").value;
var arttotal = (artprice * artquantity).toFixed(2) - 0;
document.getElementById("artprice").innerHTML = "$" + arttotal;
document.getElementById("subtotal").innerHTML = "$" + subtotal;
}
function loverupdate() {
var subtotal = arttotal + lovertotal + nighttotal;
var loverprice = 19.95;
var loverquantity = document.getElementById("loverquantity").value;
var lovertotal = (loverprice * loverquantity).toFixed(2) - 0;
document.getElementById("loverprice").innerHTML = "$" + lovertotal;
document.getElementById("subtotal").innerHTML = "$" + subtotal;
}
function nightupdate() {
var subtotal = arttotal + lovertotal + nighttotal;
var nightprice = 32.00;
var nightquantity = document.getElementById("nightquantity").value;
var nighttotal = (nightprice * nightquantity).toFixed(2) - 0;
document.getElementById("nightprice").innerHTML = "$" + nighttotal;
document.getElementById("subtotal").innerHTML = subtotal;
}
var subtotal = arttotal + lovertotal + nighttotal;
document.getElementById("subtotal").innerHTML = "$" + subtotal;
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
Here is a complete solution DEMO
Please tell me the tax so I can add that to the script
Note the changes to the html and to the script.
to add new books, follow the structure you have now.
JavaScript – replaces two of your js files: