Skip to content

Console log resolving calculation Issues in jQuery 2.2.4? #4429

@bhagathsinghs

Description

@bhagathsinghs

Description

I loaded form html page dynamically to main page using Ajax and i do not display to my user. Then from main page if user changes any of form values it will change/affect the input field in form html page.

And I have a jQuery script code on my form page like below,

$('input').change(function(){
oneCostFunction();
twoCostFunction();
consumableCost();
getTotalCost();
getTotalCostSavings();

});

and each method has different kind of calculation logic. I am getting issue in calculation when i change the value from Main page.

But if i include console.log('something') on any one of my functions it returns accurate calculation and no issues in calculation. see below my code

function getTotalCost(){
				
	for (i = 0; i <8; i++) { 
		console.log(i);
						
		$('#tcpfc_'+i).text((parseFloat($('#ccpfc_'+i).text())+parseFloat($('#sg_cpfc_'+i).text())+parseFloat($('#pgc_'+i).text())+parseFloat($('#total_ec_'+i).text())));
	}
	for (k = 8; k <16; k++) { 
		$('#tcpfc_'+k).text((parseFloat($('#ccpfc_'+k).text())+parseFloat($('#sg_cpfc_'+k).text())+parseFloat($('#pgc_'+k).text())+parseFloat($('#total_ec_'+k).text())));
	}
		$('#avg_tcpfc_1').text(((parseFloat($('#tcpfc_0').text())+parseFloat($('#tcpfc_1').text())+parseFloat($('#tcpfc_2').text())+parseFloat($('#tcpfc_3').text())+parseFloat($('#tcpfc_4').text())+parseFloat($('#tcpfc_5').text())+parseFloat($('#tcpfc_6').text())+parseFloat($('#tcpfc_7').text()))/8));
		$('#avg_tcpfc_2').text(((parseFloat($('#tcpfc_8').text())+parseFloat($('#tcpfc_9').text())+parseFloat($('#tcpfc_10').text())+parseFloat($('#tcpfc_11').text())+parseFloat($('#tcpfc_12').text())+parseFloat($('#tcpfc_13').text())+parseFloat($('#tcpfc_14').text())+parseFloat($('#tcpfc_15').text()))/8));
					
	for (k = 0; k <8; k++) { 
							
		$('#savings_'+k).text(((1-($('#tcpfc_'+(k+8)).text() / $('#tcpfc_'+k).text()))*100));
		$('#savings_'+k).text(Math.ceil(parseInt($('#savings_'+k).text()))+'%');
	}
	$('#avg_savings_1').text(Math.ceil(((1-($('#avg_tcpfc_2').text() /$('#avg_tcpfc_1').text()))*100))+'%');
}

I am wondering that what is an issue on this and how i can resolve without using console.log() code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions