Copy link to clipboard
Copied
I have checkboxes K1 add-up checkbox, K2 add-up checkbox...K20 add-up checkbox I also have text fields formated for numbers which are K1, K2...K20. Finally, I have text fields formated for numbers which are K1_, K2_...K20_.
Numbers will be entered into K1, K2, etc. Those numbers will copy into K1_, K2, etc. So far, so good. If I check the K1 add-up checkbox, I would like the number copied into K1_ to change to zero. I am using the following custom calculation script in K1_:
if (this.getField("K1 add-up checkbox").isBoxChecked(0)) {
event.value = 0;
}
So far, this also works. The problem is that if I check more than one checkbox, say K1 add-up checkbox and K2 add-up checkbox, the zero goes away in K2 add-up checkbox and it reverts to the number that is being copied from K2.
Hopefully, I have explained this sufficiently for someone to help me with what is going. I'm thinking it mus have something to do with the custom calculation script. Thanks for any help.
Copy link to clipboard
Copied
The only code that sets the "K1_" field should be in the calculation script for the "K1_" field. And that code should never use this.getField("K1_") . Field values in a calculation are set through "event.value".
Please use this script, and only this script in the "K1_" field.
if (this.getField("K1 add-up checkbox").isBoxChecked(0))
event.value = 0;
else
event.value = this.getField("K1").value;
You can read about calculations here:
https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm
Copy link to clipboard
Copied
How are you copying the number from K2 into K1_?
By the way, these are pretty confusing field names... You should consider something a bit more descriptive, but that's a different issue.
Copy link to clipboard
Copied
The number is copied using this custom calculation script: getField("K1_").value = getField("K1").valueAsString;
This is part of a 200+ page document, so the field names do have significance in the overall document (reference to the name of the schedule and the item in the schedule).
Copy link to clipboard
Copied
If that calculation is on the "K1_" field, then it needs to use "event.value" to set the field value.
If it is not on the "K1_" field, then it needs to be removed.
Use the calculation for the "K1_" field provided above.
Copy link to clipboard
Copied
You have conflicting calculations, then. You need to consolidate everything to a single script where you enter all of the logic of what value this field should have, and under what circumstances.
Copy link to clipboard
Copied
In general, it sounds like your scripts are walking on top of each other.
If the calculation script is used, then only the calculation script should set the field value. If code somewhere else is setting the same field value, the scripts will have a conflict.
Something like this: calculation for "K1_". and this is the only script that sets the "K1_" value.
if (this.getField("K1 add-up checkbox").isBoxChecked(0)) {
event.value = 0;
}
else
event.value = this.getField("K1").value;
Copy link to clipboard
Copied
That doesn't seem to help. I'm thinking that there may be conflicting code as the full code that is in the K1_ field is:
getField("K1_").value = getField("K1").valueAsString;
if (this.getField("K1_ add-up checkbox").isBoxChecked(0)) {
event.value = 0;
}
If this is causing the problem, can the
if (this.getField("K1_ add-up checkbox").isBoxChecked(0)) {
event.value = 0;
}
be put somewhere in the "K1 add-up checkbox" as script so that "K1_" turns to zero when it is checked?
Copy link to clipboard
Copied
As I think about it, putting the code into the checkbox probably won't help as the "getField("K1_").value = getField("K1").valueAsString;" still needs to be in the "K1_" field. Thus, the conflict will persist.
Here's what I'm trying to accomplish: If I enter a number in K1, want it to copy into K1_. However, if I tick the checkbox, K1 should still contain the number and K1_ should change to zero. The fields can't both be named K1 since if the checkbox is ticked, K1 should contain the number and K1_ should contain a zero. Maybe there's a simpler way to do this.
Copy link to clipboard
Copied
The only code that sets the "K1_" field should be in the calculation script for the "K1_" field. And that code should never use this.getField("K1_") . Field values in a calculation are set through "event.value".
Please use this script, and only this script in the "K1_" field.
if (this.getField("K1 add-up checkbox").isBoxChecked(0))
event.value = 0;
else
event.value = this.getField("K1").value;
You can read about calculations here:
https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm
Copy link to clipboard
Copied
That works. Thank you!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more