JavaScript to calculate car lease keeps returning NaN please help..

[ad_1]

JavaScript to calculate car lease keeps returning NaN please help..

Hey guys

I have a problem that keeps biting me in my ass… I’ve tried to incorporate a leasing(car rental) calc and I have successfully imported all the right values and fixed all the errors I see in the console. Now it keeps returning NaN in the field it’s supposed to calculate the numbers in.

​

Im using dynamic.ioo link for how they call and return functions in their doc –> [https://help.dynamic.ooo/en/articles/5323865-js-field-for-elementor-pro-form])

​

​

Thanks a lot!

website link for the referenced calc: [http://djbleasing.digitalboulevard.dk/biler/golf])

This is my Java script anyone willing to take a look at what I’m doing wrong?

​

TLDR: js keeps returning NaN and not the result..

​

function custom_js_field() {
// Set the lease duration, km allowance, and total cost variables
var leaseDuration = getField(“periode”).val();
var kmAllowance = getField(“kilometer”).val();
var downPayment = getField(“udbetaling”).val();
var totalCost;

// Set the total cost based on the lease duration
if (leaseDuration == 12) {
totalCost = getField(“total_12”).val();
} else if (leaseDuration == 24) {
totalCost = getField(“total_24”).val();
} else if (leaseDuration == 36) {
totalCost = getField(“total_36”).val();
}
// Calculate the monthly cost
function calculateMonthlyCost() {
var monthlyCost = (totalCost – downPayment) / leaseDuration;

// Calculate the excess km charge
var excessKmCharge = (kmAllowance – 20000) * 0.10;

// Add the excess km charge to the monthly cost
monthlyCost += excessKmCharge;

// Display the monthly cost
console.log(monthlyCost);
}

// Listen for changes to the sliders and dropdown
$(‘#down-payment-slider’).on(‘input’, calculateMonthlyCost);
$(‘#km-allowance-slider’).on(‘input’, calculateMonthlyCost);
$(‘#lease-duration’).on(‘change’, calculateMonthlyCost);
}
return () => { return getField(“monthlyCost”, true);}

[ad_2]
2 Comments
  1. Without thoroughly degubbing, have you tried forcing input values to int using parseInt()?

  2. You’ll have better luck getting someone to look at this if you post it on and drop a link

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer