I’m trying to calculate several input values together using jQuery. I’ve managed to make it work apart from the number contained within <input type="number" class="booking-input"/>
. It just will not add to the grand total!
Here is my function:
function checkChecked() {
var check_val = $('.ck-button input:checked').length;
var priceEvent = "<?php echo $pricePer; ?>";
var numberVal = $('.booking-input').val();
if(check_val == "") {
var check_val = numberVal;
}
if($('#bcDesign').is(':checked')) {
var design = 90;
}else{
var design = 0;
}
var totalVal = check_val * priceEvent + design;
var stripeTotalVal = totalVal * 100;
$("#totalPrice").html(commaSeparateNumber(totalVal));
$('#grandTotal').val(stripeTotalVal);
}
By wrapping it inside $(".booking-input:input, .ck-button input:checked, #bcDesign, #myDesign").change(function () {
I can get it to work, however when my form has an error (i.e. a required input box is empty) the total value of course goes back to 0 and will not update until something gets “changed”.
Any help on this one would be appreciated!