Javascript qty price multiplication
—-- JS
jQuery(function() {
initSubtotlaCalc();
});
// subtotla calculation init
function initSubtotlaCalc() {
var qtyInput = jQuery('.quantity .qty'),
singlePrice = document.getElementById('product-single-price'),
dozenPrice = document.getElementById('product-half-dozen-price'),
subtotalPrice = document.getElementById('subtotal-price');
qtyInput.on( "input",function (e) {
if( qtyInput.val() < 6 )
{
var svalue = qtyInput.val()*singlePrice.innerHTML;
subtotalPrice.innerHTML = svalue.toFixed(2);
}else{
var dvalue = qtyInput.val()*dozenPrice.innerHTML;
subtotalPrice.innerHTML = dvalue.toFixed(2);
}
});
}
—-- HTML
<span class="price"><span id="product-single-price">2</span></span>
<span class="price"><span id="product-half-dozen-price">1</span></span>
<span class="price"><span id="subtotal-price">2</span></span>
<input type="number" class="input-text qty text" value="1" title="Qty"/>