Copy link to clipboard
Copied
I need to translate the following into javascript for a pdf form I am working on that calculates monthly costs based on two different rate factors.
Can you help translate the following into javascritp?
if (cost) is < or = 130000 multiply by .02037977 else if cost is > 130000 but < or = 260000 multiply by .02037981
Thanks in advance for your help.
Copy link to clipboard
Copied
Then try this as 'Validation' script of that field:
if(event.value == "")event.value = 0;
else if(Number(event.value) > 0 && Number(event.value) <= 130000)
event.value = Number(event.value)*.02037977;
else if(Number(event.value) <= 260000)
event.value = Number(event.value)*.02037981;
Copy link to clipboard
Copied
> You can't have space in variable name.
Copy link to clipboard
Copied
Like this:
if(event.value == "") this.getField("NEXT60MOS").value = 0;
else if(Number(event.value) > 0 && Number(event.value) <= 130000)
this.getField("NEXT60MOS").value = Number(event.value)*.02037977;
else if(Number(event.value) <= 260000)
this.getField("NEXT60MOS").value = Number(event.value)*.02037981;
Copy link to clipboard
Copied
Sorry I should have been more specific. I can change the long field name to NEXT60MOS or something shorter. How does that effect the script?
Copy link to clipboard
Copied
Like this:
if(event.value == "") this.getField("NEXT60MOS").value = 0;
else if(Number(event.value) > 0 && Number(event.value) <= 130000)
this.getField("NEXT60MOS").value = Number(event.value)*.02037977;
else if(Number(event.value) <= 260000)
this.getField("NEXT60MOS").value = Number(event.value)*.02037981;
Copy link to clipboard
Copied
Doesnt seem to be doing the calculation with that formula:
Copy link to clipboard
Copied
Were are you running the script from?
The script should be executed in the Validation section of the CARM COST field.
Just for troubleshooting purposes, if you do have it as Validation script, move the entire script to custom calculation script.
If there is nothing wrong with the script it should apply any calculations immediately and display the result in the NEXT60MOS field with no errors.
Copy link to clipboard
Copied
THAT WORKED! Thank you so much for your time and your patience with me. So very much appreciated. All the best to you.
Copy link to clipboard
Copied
You're welcome.
Kudos to Nesa Nurani and Try67 for their valuable guidance all the time.
Copy link to clipboard
Copied
Ok great.
Copy link to clipboard
Copied
Looking for help again. The formula below works for this financing calclulation but need to add deferral field to the form. So below is for 0 months before payment (no deferral) and I'll need to add a 1, 2 and 3 month deferral to the calulator. The field is called "Mos before payment" so if I do and IF term is 60 AND Mos before payment is 0... how would I add that to the script below. Then repeat it for all the terms and months deferred. Any ideas?
if (this.getField("Term").value == "60") {this.getField("MonthlyPayments").value = (this.getField("60 mo rate factor").value) * (this.getField("Purchase Price - DownPayment").value); }
else if (this.getField("Term").value == "72") {this.getField("MonthlyPayments").value = (this.getField("72 mo rate factor").value) * (this.getField("Purchase Price - DownPayment").value); }
else if (this.getField("Term").value == "84") {this.getField("MonthlyPayments").value = (this.getField("84 mo rate factor").value) * (this.getField("Purchase Price - DownPayment").value); }