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

If a Field is grater than or less than

New Here ,
Sep 15, 2024 Sep 15, 2024

Copy link to clipboard

Copied

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

Views

196

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

correct answers 1 Correct answer

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 = "";

 

 

Votes

Translate

Translate
Community Expert ,
Sep 15, 2024 Sep 15, 2024

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

The value of the  "numofmonnths" field 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

LATEST

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

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

Copy link to clipboard

Copied

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 = "";

 

 

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