Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery calculator script example

0 votes
2 views
added Nov 8 in jQuery by LC Marshal Lieutenant (14,630 points)
jQuery(document).ready(function( $ ) {
	$('.top-desktop').matchHeight();
	$('.bottom-desktop').matchHeight();
	calculator_buy_update();
	function calculator_buy_update() { 
		buy_propertyprice = parseInt(accounting.unformat($("#buy_prop-price").val(), 0));
		buy_AHVArate = parseInt($("#buy_hva-rate").val());
		buy_youpay = 0.2 * buy_propertyprice;
		//newMarketValue = propertyprice * (Math.pow((1+(AHVArate/100)) ,5));
		buy_foo = Math.pow((1+(buy_AHVArate/100)) ,5);
		buy_newMarketValue = buy_propertyprice * buy_foo;
		buy_amtPaidByInvestor = 0.80 * buy_propertyprice;
		buy_totalCapitalGain = (buy_propertyprice*buy_foo)-buy_propertyprice;
		if(buy_AHVArate<0){
			buy_attToDeveloper = 0;
			buy_attToBuyer= Math.max(-0.20*buy_propertyprice, buy_totalCapitalGain);
			buy_attToInvestor = buy_totalCapitalGain - buy_attToBuyer;
		}else{
			buy_attToDeveloper = Math.min(buy_totalCapitalGain, 0.20*buy_propertyprice)
			buy_attToBuyer = 0.20 * Math.max(0, buy_totalCapitalGain - buy_attToDeveloper);
			buy_attToInvestor = 0.80 * Math.max(0, buy_totalCapitalGain - buy_attToDeveloper);
		}
		buy_yourShareOfCapitalGain = buy_attToBuyer;
		buy_youWillSave = 0.045 * 5 * buy_propertyprice;
		buy_yourTotalGain = buy_youWillSave + buy_attToBuyer;
		buy_amtOwnedToInvestors = buy_amtPaidByInvestor + buy_attToInvestor + buy_attToDeveloper;
		buy_fundtarget = buy_propertyprice - buy_youpay;
		buy_homevalue = buy_propertyprice + buy_totalCapitalGain;
		// console.log("ArrtBuyer:" + attToBuyer + "; ArrtInvestor" + attToInvestor + "; attToDeveloper" + attToDeveloper );
		buy_roi = ((buy_yourTotalGain - buy_youpay)/buy_youpay)*100;

		$(".buy_youpay").html("RM " + accounting.formatNumber(buy_youpay, 0));
		$(".buy_capitalgain").html("RM " + accounting.formatNumber(buy_yourShareOfCapitalGain, 0));
		$(".buy_yousave").html("RM " + accounting.formatNumber(buy_youWillSave, 0));
		$(".buy_totalgain").html("RM " + accounting.formatNumber(buy_yourTotalGain, 0));
		// $(".topup").html("RM " + topupSeperated);
		$(".buy_fundtarget").html("RM " + accounting.formatNumber(buy_fundtarget, 0));
		$(".buy_ahvarate").html(buy_AHVArate + "%");
		$(".buy_homevalue").html("RM " + accounting.formatNumber(buy_homevalue, 0));
		$(".buy_topup").html("RM" + accounting.formatNumber(buy_amtOwnedToInvestors, 0));
		$(".buy_roi").html(buy_roi.toFixed(2) + "%");
	}
	$( "#buy_property-price" ).slider({
		orientation: "horizontal",
		range: "min",
	  	min: 200000,
		max: 5000000,
		value: 200000,
			slide: function( event, ui ) {
				// $( "#buy_prop-price" ).val( "RM " + ui.value );
				$("#buy_prop-price").val(accounting.formatNumber(ui.value, 0));
				$("#buy_prop-price").tooltip('hide');
				calculator_buy_update();
			}
	});
	$( "#buy_apprreciation-rate" ).slider({
		orientation: "horizontal",
		range: "min",
		min: -10,
		max: 10,
		value: 0,
	  	slide: function( event, ui ) {
        // $( "#hva-rate" ).val( ui.value + "%");
				$("#buy_hva-rate").val( ui.value );
				$("#buy_hva-rate").tooltip('hide');
				calculator_buy_update();
      }
	});

	$( "#buy_prop-price" ).on( "change", function() {
		$(this).tooltip({
			trigger : 'manual',
			title: "Enter a valid number between 200000 to 5000000"
		});
		field_value = accounting.unformat(this.value);
		if(field_value >=200000 && field_value<=5000000){
			$( "#buy_property-price" ).slider( "value", field_value );
			calculator_buy_update();
			$(this).tooltip('hide');
		}else{
			$(this).tooltip('show');
		}
	});
	$( "#buy_hva-rate" ).on( "change", function() {
		$(this).tooltip({
			trigger : 'manual',
			title: "Enter a valid number between -10 to +10"
		});
		if(this.value <=10 && this.value>=-10){
			$( "#buy_apprreciation-rate" ).slider( "value", this.value );
			calculator_buy_update();
			$(this).tooltip('hide');
		}else{
			$(this).tooltip('show');
		}
	});

	// $("#property-price").slider( "value", 200000 );
	$("#buy_property-price" ).slider( "value", $("#buy_prop-price").val());
	$("#buy_apprreciation-rate" ).slider( "value", $("#buy_hva-rate").val());
	// $("#apprreciation-rate").slider( "value", 5 );

	// FOR INVESTORS
	calculator_fund_update();
	function calculator_fund_update() { 
		fund_propertyPrice = parseInt(accounting.unformat($("#fund_prop-price").val(), 0));
		fund_investmentAmmount = parseInt(accounting.unformat($("#fund_investment-amt").val(), 0));
		fund_annualGrowth = parseInt($("#fund_annual-growth").val());

		fund_foo = Math.pow((1+(fund_annualGrowth/100)) ,5);
		fund_newMarketValue = fund_propertyPrice * fund_foo;
		fund_amtPaidByInvestor = 0.80 * fund_propertyPrice;
		fund_totalCapitalGain = (fund_propertyPrice*fund_foo)-fund_propertyPrice;
		if(fund_annualGrowth<0){
			fund_attToDeveloper = 0;
			fund_attToBuyer= Math.max(-0.20*fund_propertyPrice, fund_totalCapitalGain);
			fund_attToInvestor = fund_totalCapitalGain - fund_attToBuyer;
		}else{
			fund_attToDeveloper = Math.min(fund_totalCapitalGain, 0.20*fund_propertyPrice)
			fund_attToBuyer = 0.20 * Math.max(0, fund_totalCapitalGain - fund_attToDeveloper);
			fund_attToInvestor = 0.80 * Math.max(0, fund_totalCapitalGain - fund_attToDeveloper);
		}

		fund_changeInValue = fund_totalCapitalGain;
		fund_yourShareOfChangeInValue = fund_attToInvestor * (fund_investmentAmmount/(0.8*fund_propertyPrice));
		fund_earningOver5yrs = 0.05 * fund_investmentAmmount  * 5;
		fund_totalGain = fund_yourShareOfChangeInValue + fund_earningOver5yrs;
		// console.log("ArrtBuyer:" + fund_attToBuyer + "; ArrtInvestor" + fund_attToInvestor + "; attToDeveloper" + fund_attToDeveloper );
	
		$(".fund_propprice").html("RM " + accounting.formatNumber(fund_propertyPrice, 0));
		$(".fund_youinvest").html("RM " + accounting.formatNumber(fund_investmentAmmount, 0));
		$(".fund_changeinvalue").html("RM " + accounting.formatNumber(fund_changeInValue, 0));
		$(".fund_shareinchangeinvalue").html("RM " + accounting.formatNumber(fund_yourShareOfChangeInValue, 0));
		$(".fund_yourearnings").html("RM " + accounting.formatNumber(fund_earningOver5yrs, 0));
		$(".fund_totalgain").html("RM " + accounting.formatNumber(fund_totalGain, 0));
		$(".fund_propertyprice").html("RM " + accounting.formatNumber(fund_totalGain, 0));
		$(".fund_annualGrowth").html(fund_annualGrowth + "%");
		// $(".buy_homevalue").html("RM " + accounting.formatNumber(buy_homevalue, 0));
		// $(".buy_roi").html(buy_roi.toFixed(2) + "%");
	}
	$( "#fund_property-price" ).slider({
		orientation: "horizontal",
		range: "min",
		min: 200000,
		max: 5000000,
		value: 200000,
		slide: function( event, ui ) {
			// $( "#prop-price" ).val( "RM " + ui.value );
			$("#fund_prop-price").val(accounting.formatNumber(ui.value, 0));
			$("#fund_prop-price").tooltip('hide');
			calculator_fund_update();
		}
	});
	$( "#fund_investment-ammount" ).slider({
		orientation: "horizontal",
		range: "min",
		min: 1000,
		max: 1000000,
		value: 200000,
		slide: function( event, ui ) {
			// $( "#prop-price" ).val( "RM " + ui.value );
			$( "#fund_investment-amt" ).val( accounting.formatNumber(ui.value, 0) );
			$("#fund_investment-amt").tooltip('hide');
			calculator_fund_update();
		}
	});
	$( "#fund_annual-growth-rate" ).slider({
		orientation: "horizontal",
		range: "min",
		min: -10,
		max: 10,
		value: 0,
		slide: function( event, ui ) {
		// $( "#hva-rate" ).val( ui.value + "%");
				$( "#fund_annual-growth" ).val( ui.value );
				$("#fund_annual-growth").tooltip('hide');
				calculator_fund_update();
		}
	});

	$( "#fund_prop-price" ).on( "change", function() {
		$(this).tooltip({
			trigger : 'manual',
			title: "Enter a valid number between 200000 to 5000000"
		});
		field_value = accounting.unformat(this.value);
		if(field_value >=200000 && field_value<=5000000){
			$( "#fund_property-price" ).slider( "value", field_value );
			calculator_fund_update();
			$(this).tooltip('hide');
		}else{
			$(this).tooltip('show');
		}
	});

	$( "#fund_investment-amt" ).on( "change", function() {
		$(this).tooltip({
			trigger : 'manual',
			title: "Enter a valid number between 1000 to 1000000"
		});
		field_value = accounting.unformat(this.value);
		if(field_value >=1000 && field_value<=1000000){
			$( "#fund_investment-ammount" ).slider( "value", field_value );
			calculator_fund_update();
			$(this).tooltip('hide');
		}else{
			$(this).tooltip('show');
		}
	});

	$( "#fund_annual-growth" ).on( "change", function() {
		$(this).tooltip({
			trigger : 'manual',
			title: "Enter a valid number between -10 to 10"
		});
		if(this.value <=10 && this.value>=-10){
			$( "#fund_annual-growth-rate" ).slider( "value", this.value );
			calculator_fund_update();
			$(this).tooltip('hide');
		}else{
			$(this).tooltip('show');
		}
	});

	$("#fund_property-price" ).slider( "value", $("#fund_prop-price").val());
	$("#fund_investment-ammount" ).slider( "value", $("#fund_investment-amt").val());
	$("#fund_annual-growth-rate" ).slider( "value", $("#fund_annual-growth").val());

	$('.main-carousel').flickity({
		// options
		cellAlign: 'left',
		contain: true,
		pageDots: false
	});
});

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...