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

Assign a calculated value to a text field

New Here ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

HI

I am using ADOBE Acrobat Pro DC V 2018.011.20040

My aim is to manually fill out the top table i1 to i3 and j1 to j3. Then press the bottom table calculate button and the result appears in the value column beside it as a %.

Using WBC button as an example the formula is (j1WBC-j3WBC)/(i3WBC-j3WBC).

Applying the formula to the WBC value text field

.

I have proven the formula works.

However i need to put all the data into the top table before doing the calculation. My solution was to press a button, it does the calculation and assigns the value to the text field beside it.

I have set up the button properties

in the java script I have put rWBC=(j1WBC-j3WBC)/(i3WBC-j3WBC).

rWBC is the name for the text beside it.

At the moment pressing the button does nothing.

Your comments and help will be most appreciated.

Regards MH

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.2K

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

LEGEND , Jun 15, 2018 Jun 15, 2018

What do you expect to happen when the result if the calculation i3WBC - j3WBC is zero?

Also if you are calculating in the field for the result of the calculation, use "event.value" and not the field object.

var j1WBC = this.getField("j1WBC").value

var j3WBC = this.getField("j3WBC").value

var i3WBC = this.getField("i3WBC").value

var rWBC = "";

if (i3WBC-j3WBC != 0) {

     rWBC = (j1WBC-j3WBC)/(i3WBC-j3WBC)

}

event.value = rWBC;

You can also open the Acrobat JavaScript Debugging window to see any errors or

...

Votes

Translate

Translate
Community Expert ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

In JavaScript you must use this.getField(" field name ").value to access the value of a 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
Engaged ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

In JS, you first need to "define" variables and "assign" values to them before using them in a calculation

you tell JS: this is a variable (not just some characters) by using "var"

You assign a value to your variable with the assignement operator "="

And you retrieve a value from a field with the .value property of the field targeted using the getField() method

Try this instead:

var j1WBC = this.getField("j1WBC").value

var j3WBC = this.getField("j3WBC").value

var i3WBC = this.getField("i3WBC").value

var rWBC = (j1WBC-j3WBC)/(i3WBC-j3WBC)

this.getField("rWBC").value = rWBC

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
LEGEND ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

What do you expect to happen when the result if the calculation i3WBC - j3WBC is zero?

Also if you are calculating in the field for the result of the calculation, use "event.value" and not the field object.

var j1WBC = this.getField("j1WBC").value

var j3WBC = this.getField("j3WBC").value

var i3WBC = this.getField("i3WBC").value

var rWBC = "";

if (i3WBC-j3WBC != 0) {

     rWBC = (j1WBC-j3WBC)/(i3WBC-j3WBC)

}

event.value = rWBC;

You can also open the Acrobat JavaScript Debugging window to see any errors or messages being thrown by your script.

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 ,
Jun 16, 2018 Jun 16, 2018

Copy link to clipboard

Copied

LATEST

Hi All,

A big thanks for all your help. The script works!!!

Regards Michael

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