Copy link to clipboard
Copied
I have 3 text fields in a pdf and I named them each Adjustments_1 , Adjustments_2 and Adjustments_3. I want Adjustments_3 to equal Adjustments_1 - Adjustments_2 and if that difference is less than 0, I want Adjustments_3 to equal "0" and have that difference displayed on the text fields. I tried doing an if else statement under the custom calculation script in the Adjustments_3 properties which looks like this:
if (Adjustments_2 < Adjustments_1) {
Adjustments_3=Adjustments_1-Adjustments_2;
}
else {
Adjustments_3 = "0";
}
My difference is always 0.00 for any value I try, so I'm just wondering where I went wrong.
You cannot access the value of a field by just using the field name. The correct way to get the value of a field is this:
this.getField("Adjustment_1").value
So, to convert your calculation to this mechanism, by also introducing JavaScript variables, the script would look like this:
...var Adjustment_1 = this.getField("Adjustment_1").value;
var Adjustment_2 = this.getField("Adjustment_2").value;
var Adjustment_3;
if (Adjustments_2 < Adjustments_1) {
Adjustments_3=Adjustments_1-Adjustments_2;
}
else {
Copy link to clipboard
Copied
You cannot access the value of a field by just using the field name. The correct way to get the value of a field is this:
this.getField("Adjustment_1").value
So, to convert your calculation to this mechanism, by also introducing JavaScript variables, the script would look like this:
var Adjustment_1 = this.getField("Adjustment_1").value;
var Adjustment_2 = this.getField("Adjustment_2").value;
var Adjustment_3;
if (Adjustments_2 < Adjustments_1) {
Adjustments_3=Adjustments_1-Adjustments_2;
}
else {
Adjustments_3 = "0";
}
this.getField("Adjustment_3").value = Adjustment_3;
As you can see, I've left your script intact, and created variables with the names that you've used, but either assigned these variables based on the field value, or assigned the field value based on the variable Adjustment_3.
Copy link to clipboard
Copied
Thank you so much, it worked perfectly!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now