Why is it showing NaN unless I put the value as zero here? I'd like it to keep a running total and just display the placeholder but unless I put the value of the inputs to 0 then it shows up as NaN in the total div where the total displays?
$("body").on("blur", "#serviceContract,#gapInsurance,#extendedWarranty,#amtOwedOnTrade,#tradeInValue,#manufacturerRebate,#downPayment,#estimatedTaxesAndFees,#vehiclePrice",function() {
updateTotal();
});
var updateTotal = function() {
var input1 = parseInt($('#vehiclePrice').val());
var input2 = parseInt($('#estimatedTaxesAndFees').val());
var input3 = parseInt($('#downPayment').val());
var input4 = parseInt($('#manufacturerRebate').val());
var input5 = parseInt($('#tradeInValue').val());
var input6 = parseInt($('#amtOwedOnTrade').val());
var input7 = parseInt($('#extendedWarranty').val());
var input8 = parseInt($('#gapInsurance').val());
var input9 = parseInt($('#serviceContract').val());
if (input1 ==undefined || input2 == undefined || input3 == undefined || input4 == undefined || input5 == undefined || input6 == undefined || input7 == undefined || input8 == undefined ||input9 == undefined ) {
$('#total').text(total);
} else {
var max = 40000;
var total = input1 + input2 - input3 - input4 - input5 + input6 + input7 + input8 + input9;
if (total > max) {
$('#total').text('The maximum is ' + max);
$('#total1').val(40000);
} else {
$('#total').text(total);
$('#total1').val(total);
}
}
};