Skip to main content
Participant
March 5, 2020
Question

If statement in Adobe Forms

  • March 5, 2020
  • 1 reply
  • 567 views

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?

This topic has been closed for replies.

1 reply

ls_rbls
Community Expert
Community Expert
March 5, 2020

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;

 

Thom Parker
Community Expert
Community Expert
March 6, 2020

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
ls_rbls
Community Expert
Community Expert
March 6, 2020

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.