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

JavaScript Calculation Help

Community Beginner ,
Jul 29, 2021 Jul 29, 2021

I am trying to write this JavaScript code in our adobe PDF to ensure it pulls from different text boxes that are filled in when completing the document and then calculated together at the bottom. My experience with JavaScript is little to none so I have been looking at training videos and testing so many different scripts. 

 

So far this is what I have - the words like Pay, BR, HW, Salary, and Fee are defined within the document itself and is defined when someone fills out the form, adding that information:

let HC = 'Pay*1.37';
let GM = 'BR-HC';
let CP = 'GM*HW';
let TF = Salary*Fee
TF-CP;

 

I am thinking my issue is not telling it to calculate TF - CP so it is therefore not providing me with any final calculations. Any assistance here would really help me figure out where I went wrong. 

TOPICS
How to
795
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 ,
Jul 29, 2021 Jul 29, 2021

To add up to mentioned above, also use 'var' instead of 'let' and if you want to show result of TF-CP in field use event.value,

This is just example script:

var HC = this.getField("Pay").value*1.37;
var GM = this.getField("BR").value-HC;
var CP = GM*this.getField("HW").value;
var TF = this.getField("Salary").value*this.getField("Fee").value;
event.value = TF-CP;

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 ,
Jul 29, 2021 Jul 29, 2021

To access the value of a field you must use:

this.getField(" field name ").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
Community Beginner ,
Jul 30, 2021 Jul 30, 2021
LATEST

Thank you so much!

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 ,
Jul 29, 2021 Jul 29, 2021

To add up to mentioned above, also use 'var' instead of 'let' and if you want to show result of TF-CP in field use event.value,

This is just example script:

var HC = this.getField("Pay").value*1.37;
var GM = this.getField("BR").value-HC;
var CP = GM*this.getField("HW").value;
var TF = this.getField("Salary").value*this.getField("Fee").value;
event.value = TF-CP;

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 Beginner ,
Jul 30, 2021 Jul 30, 2021

That makes so much more sense! Girl you are a life saver! I can't be more grateful for you!

 

I looked high and low for tutorials to see what I was doing wrong!

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