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

If a Field is grater than or less than

New Here ,
Sep 15, 2024 Sep 15, 2024

I'm still learning and I have messed this up.

 

I have a field labeled "numofmonths".  I am trying to create a javascript that says if "numofmonths" is = 2, the value of the "results" field is 5% but if the "numofmonths" is greater than or equal to 3 the "result" field is 10%

 

Can someone help me?

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms
495
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 15, 2024 Sep 15, 2024

Use this as custom calculation script of 'result' field:

 

 

var n = Number(this.getField("numofmonths").valueAsString);

if(n === 2)
 event.value = n*0.05;
else if(n > 2)
 event.value = n*0.1;
else
 event.value = "";

 

 

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 ,
Sep 15, 2024 Sep 15, 2024

Percentage of what 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
New Here ,
Sep 15, 2024 Sep 15, 2024

The value of the  "numofmonnths" field 

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 ,
Sep 15, 2024 Sep 15, 2024

What it is less than 2?  What if it is greater than 2 and less than 3?

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
New Here ,
Sep 15, 2024 Sep 15, 2024

I see what you mean,  I made it. Confusing...


The "numofmonths" counts the number of months. 

if the "numofmonths" is less than 2 then the "result " field = 0

if the "nunofmonths" equals 2 then the "result"  field = 5%

if the "numofmonths" is greater than 2 the "result" field = 10%

 

I hope that makes sense.. can you help me figure it out?

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 ,
Sep 15, 2024 Sep 15, 2024
LATEST

If this explanation is the last one, try using the script I posted, it should do what you're asking for.

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 ,
Sep 15, 2024 Sep 15, 2024

Use this as custom calculation script of 'result' field:

 

 

var n = Number(this.getField("numofmonths").valueAsString);

if(n === 2)
 event.value = n*0.05;
else if(n > 2)
 event.value = n*0.1;
else
 event.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