I have three input field in a page, they appear (.append) in different combinations and there is a fourth div that shows the sum of that combination: it could be: a (is always on), a+b, a+c, a+b+c. I'm using if/else if statement but idoesn't work for a+b+c. Can someone help? thanks. The code i'm using:
$( document ).ready(function() {
$(".page").on("change keyup keydown paste propertychange bind mouseover", function(){
var iva4 = $("#total_amount").val();
var iva22 = $("#total22_amount").val();
var iva0 = $("#total0_amount").val();
if (($("#total_amount").length) && ($("#total22_amount").length)) {
var totaleIva = (parseFloat(iva4) + parseFloat(iva22));
} else if (($("#total_amount").length) && ($("#total0_amount").length)) {
var totaleIva = (parseFloat(iva4) + parseFloat(iva0));
} else if ((("total_amount").length) && ($("#total0_amount").length) && ($("#total22_amount").length) ) {
var totaleIva = (parseFloat(iva4) + parseFloat(iva22) + parseFloat(iva0));
}
$("#totale-somma").val(parseFloat(totaleIva).toFixed(2));
if( !$.trim( $('.subtotale').html() ).length ) {
$('#somma-finale').css("display", "none");
} else {
$('#somma-finale').css("display", "block");
}
});
});
total_amount,total22_amountandtotal0_amountare getting created dynamically? and is there possibility that any of them may not be present in html DOM?