Refreshing calculation field when using JS/PHP

Hi everyone I’m running into some issues when combining both the built-in calculation functions in the form along with my own logic that utilizes different numbers in each field depending on dropdown choices that a user makes.

When the form is submitted, the number is reflected accurately and everything is correct, but while the user is filling out the form, my javascript numbers aren’t being reflected in gravity’s calculation.

So for my question: Is there anyway to refresh the calculation field?

I’ve tried moving the script into an html field so that it doesn’t just update on the server-side, but I’m still getting the same issue where my total amount doesn’t update on the client-side.

add_action('wp_footer','gf_custom_script');
//add_filter('gform_calculation_result', 'gf_custom_script'); trying to override calculation of front-end 
function gf_custom_script(){ //this is for commission disbursement request REAL ESTATE
	?>
	<script type="text/javascript">
		jQuery('document').ready(function(){
			jQuery('#input_6_5, #input_6_17, #input_6_178').change(function(){
				//input_6_5 is sale price 
                //input_6_17 is property type 
				var sale_price = jQuery('#input_6_5').val();
				var property_type = jQuery('#input_6_17').val();
				var insurance_fee = jQuery('#input_6_77').val(); //E&O Insurance/Risk Management Fee
				var smart_buy_combo = jQuery('#input_6_178').val(); //smart-buy combo choice from user 
				var regex = /\d+(?:\.\d+)?/g;
				var match;	
				var matchArray="";
				//var match = regex.exec(sale_price);
                //the exec method executes a search for a match in a specified string and returns a result array or null
				while (match = regex.exec(sale_price)) {
					matchArray+=match[0];
				  
				}
				//var formated_string = match.join('-');
				//pricing = formated_string.replace("-", ""); 
				var broker_commission = calculate_broker_commission(matchArray,property_type);
				var eo_insurance = calculate_eo_insurance(property_type);
				var smart_buy = calculate_smart_buy(smart_buy_combo);
				jQuery('#input_6_179').val(smart_buy); //for smart-buy calculation
				jQuery('#input_6_177').val("+$"+smart_buy); // for smart-buy front-end
				jQuery('#input_6_77').val(-eo_insurance); //for calculation
				jQuery('#input_6_175').val("-$"+eo_insurance); //separate field for visibility
				jQuery('#input_6_141').val("-$"+broker_commission); //this is also company dollar 
				jQuery('#input_6_24').val(-broker_commission); //this is company dollar (hidden) used for calculation
				
				
			});	
                         
			function calculate_broker_commission(sale_price,property_type){
				if(property_type == 'Residential 1-4 Units'){
					if(sale_price >= 0 &&  sale_price <= 1000000 ){
						return 495;	
					}else{
						var sale_price_cal = sale_price/1000000;
						var cal = sale_price_cal.toString();

						if(cal.indexOf('.') !== -1){
							price_array = cal.split('.');
							var divisible = parseInt(price_array[0]) + 1;
							return 495*divisible;
						}else{
							return 495*sale_price_cal;	
						}
					}
				}else{
					b_com = jQuery('#input_6_18').val(); //broker net commission $
					var regex = /\d+(?:\.\d+)?/g;
					var match;			
					var b_comArray = "";
					while (match = regex.exec(b_com)) {
						b_comArray+=match[0];
					  
					}	
					return b_comArray*0.2;
				}
			}

			function calculate_eo_insurance(property_type) {
    			if (property_type == 'Residential 1-4 Units') {
        			return 170
    			}else if (property_type == 'Residential 1-4 Units (Smart-Buy Referral)') {
        			return 170;
    			}else if(property_type == 'Residential 1-4 Units Lease'){
					return 170;
				}else {
        			return 270;
    			}
			}

			function calculate_smart_buy(smartbuy){
				if(smartbuy == 'Yes'){
					return 300;
				}else{
					return 0;
				}
			}

		});
	</script>
	<?php
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.