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

Javascript formula

Community Beginner ,
Nov 07, 2022 Nov 07, 2022

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.

 

TOPICS
How to , JavaScript

Views

3.0K

Translate

Translate

Report

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

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;

View solution in original post

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

> You can't have space in variable name.

View solution in original post

Votes

Translate

Translate

Report

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

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;

View solution in original post

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

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;

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Doesnt seem to be doing the calculation with that formula:

defaulthv1qy9nywblw_0-1667928653037.png

 

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You're welcome.

 

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Ok great.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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