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

If statement in Adobe Forms

New Here ,
Mar 05, 2020 Mar 05, 2020

Copy link to clipboard

Copied

I need help on two JavaScripts:

 

I have a field Num1, where people can imput their projected gross receipts.

 

On the next line, Num2, I want it to calculate that if Num1 less than 25000, it should equal 0, and if the value is over 25000, a calcuation of Num1-25000 should occur.  I've tried several JavaScripts, but I can't seem to figure out the right one.

 

Several lines down I also have a field, Num5, that I would like it to calcualte that if the value is less than 75, it should equal 75, and if it's over 500,000 it should equal 500,000.

 

Help?

TOPICS
Acrobat SDK and JavaScript

Views

255

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 ,
Mar 05, 2020 Mar 05, 2020

Copy link to clipboard

Copied

Hi,

 

Use something like this :

 

 

// CUSTOM CALC SCRIPT FOR FIELD NUM2
var a = this.getField("Num1").value;
var b = 25000;
var d =0;
if ((a <= b) && (a != 0)) event.value = b;
else if(a > b) event.value = b;
else if((a <= d) && (a < 25000)) event.value ="";
else event.value = a;



// CUSTOM CALC SCRIPT FOR FIELD NUM5
var a = this.getField("Num1").value;
var b = 75;
var c = 500000;
var d =0;
if ((a <= b) && (a != 0)) event.value = b;
else if(a > c) event.value = c;
else if((a <= d) && (a <= 75)) event.value ="";
else event.value = a;

 

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 ,
Mar 05, 2020 Mar 05, 2020

Copy link to clipboard

Copied

Why so many conditions?  The question was for only two options. 

For example:

 

var a = this.getField("Num1").value;
if (a <= 25000) 
     event.value = 0;
else  
      event.value = 25000-a;

 

You can read about calculations and "if" statements at these links:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/

https://www.acrobatusers.com/tutorials/conditional-execution/

https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Mar 05, 2020 Mar 05, 2020

Copy link to clipboard

Copied

LATEST

Yes, sorry about that.

 

I missed this part "Num1-25000"   I wasn't tracking it was a substraction so I treated Num1  like Num5 field calculation.

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