Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript formula

Community Beginner ,
Nov 07, 2022 Nov 07, 2022

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.

 

TOPICS
How to , JavaScript
3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
3 ACCEPTED SOLUTIONS
Community Expert ,
Nov 08, 2022 Nov 08, 2022

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;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

> You can't have space in variable name.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

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;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 08, 2022 Nov 08, 2022

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

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;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 08, 2022 Nov 08, 2022

Doesnt seem to be doing the calculation with that formula:

defaulthv1qy9nywblw_0-1667928653037.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 08, 2022 Nov 08, 2022

THAT WORKED! Thank you so much for your time and your patience with me. So very much appreciated. All the best to you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

You're welcome.

 

Kudos to Nesa Nurani and Try67 for their valuable guidance all the time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Ok great.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 18, 2023 Apr 18, 2023
LATEST

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); }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines