Assign a calculated value to a text field

New Here ,
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

Adobe Community Professional
Correct answer by gkaiseril | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

251

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

Assign a calculated value to a text field

New Here ,
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

Adobe Community Professional
Correct answer by gkaiseril | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

252

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
Jun 14, 2018 0
Adobe Community Professional ,
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.

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...
Jun 14, 2018 0
Engaged ,
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

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...
Jun 15, 2018 0
Adobe Community Professional ,
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.

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...
Jun 15, 2018 0
New Here ,
Jun 16, 2018

Copy link to clipboard

Copied

Hi All,

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

Regards Michael

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