Field Calculation Javascript

Community Beginner ,
Apr 09, 2020

Copy link to clipboard

Copied

Hi, 

I am in need of assistance writing a custom calculation script for a field.

My form includes two fields that include a low and a high value, and another field that has a total value. I need a script to show me the variance if the total value falls outside of the low or high. If the total value falls within the range, it should just say $0.00

 

Example: Range is $2,000.00 to $5,000.00 and the Total is $5,500.00. I need it to return $500.00. 

Can anyone help me with this?

Thank you in advance!

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

See this article:

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

 

YOu'll need somehting like this in the calculation field for the variance 

 

var total = this.getField("Total").value

if(total < 2000)

     event.value = 2000 - total;

else if (total > 5000)

    event.value = total - 5000;

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

206

Likes

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

Field Calculation Javascript

Community Beginner ,
Apr 09, 2020

Copy link to clipboard

Copied

Hi, 

I am in need of assistance writing a custom calculation script for a field.

My form includes two fields that include a low and a high value, and another field that has a total value. I need a script to show me the variance if the total value falls outside of the low or high. If the total value falls within the range, it should just say $0.00

 

Example: Range is $2,000.00 to $5,000.00 and the Total is $5,500.00. I need it to return $500.00. 

Can anyone help me with this?

Thank you in advance!

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

See this article:

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

 

YOu'll need somehting like this in the calculation field for the variance 

 

var total = this.getField("Total").value

if(total < 2000)

     event.value = 2000 - total;

else if (total > 5000)

    event.value = total - 5000;

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

207

Likes

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
Apr 09, 2020 0
Adobe Community Professional ,
Apr 09, 2020

Copy link to clipboard

Copied

See this article:

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

 

YOu'll need somehting like this in the calculation field for the variance 

 

var total = this.getField("Total").value

if(total < 2000)

     event.value = 2000 - total;

else if (total > 5000)

    event.value = total - 5000;

 

Likes

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
Reply
Loading...
Apr 09, 2020 0
Community Beginner ,
Apr 09, 2020

Copy link to clipboard

Copied

Hi Thom,

Thank you for getting back to me so quickly.

The problem that I have is the Low and High ranges (the 2000 and 5000) are form fields themselves and will vary based on the users entry.

Is the concept similar?

Likes

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
Reply
Loading...
Apr 09, 2020 0
Adobe Community Professional ,
Apr 09, 2020

Copy link to clipboard

Copied

Yes it is, the limit values are acquired and used in exactly the same way as the total

Likes

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
Reply
Loading...
Apr 09, 2020 0
bgb6 LATEST
Community Beginner ,
Apr 09, 2020

Copy link to clipboard

Copied

It worked!!! Thank you so much!

Likes

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
Reply
Loading...
Apr 09, 2020 1