Currently i can input a value into a number box and it would calculate the quantity * Price, into a subtotal field. I'm having an issue where i would like the subtotal calculated after i click on (+) and (-) buttons. what is happening is after i click the button it wont calculate the number in the quantity box, only the previous number that was there. i.e- when i click (+) it will display 1 in the quantity field, but subtotal wont change. i click (+) again the quantity will display 2, but the subtotal will display $99 which is the price of a single product. it should be displaying $198.
var total_items = 1;
function CalculateItemsValue() {
var total = 0;
for (i=1; i<=total_items; i++) {
itemID = document.getElementById("qnt_"+i);
if (typeof itemID === 'undefined' || itemID === null) {
alert("No such item - " + "qnt_"+i);
} else {
total = total + parseInt(itemID.value) * parseInt(itemID.getAttribute("data-price"));
}
}
document.getElementById("ItemsTotal").innerHTML = "$" + total;
}
<input type="button" value="-" class="qtyminus" field="qnt_1" onmouseup="CalculateItemsValue()">
<input type="number" name="qnt_1" id="qnt_1" value="0" class="qty" data-price="99.95" onkeyup="CalculateItemsValue()" oninput="validity.valid||(value='');">
<input type="button" value="+" class="qtyplus" field="qnt_1" onmouseup="CalculateItemsValue()">
<div id="ItemsTotal">$0</div>