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
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
...Copy link to clipboard
Copied
In JavaScript you must use this.getField(" field name ").value to access the value of a field.
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
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.
Copy link to clipboard
Copied
Hi All,
A big thanks for all your help. The script works!!!
Regards Michael