Copy link to clipboard
Copied
I have a box labeled HST and another for Subtotal.
I want to perform a simple math calculation on the HST box, the result displaying in the Subtotal box.
I want the user to be able to overwrite the Subtotal Box. This Subtotal box is included in the TOTAL Box calculation which is not to be overwritten.
Thanks!
Copy link to clipboard
Copied
in the custom calculation script of subtotal:
if (event.value == ""){
//Put in your calculation script
event.value = //the result of the calculation
}
Basically what you are doing is not doing the calculation if something is entered manually.
Copy link to clipboard
Copied
A calculation script always runs. And it runs each and every time a field on the form changes value. The results of a calculation can be blocked from affecting the actual field value by setting "event.rc" to false. This allows the user to override the calculation.
However, there is a trick to getting this right, which is to clearly define the circumstances under which the the calculation is overridden and released. Simply testing for an empty field value will not work it because after the first calc result it will block all following calculations.
The easy solution is to use an override checkbox.
Here is the calculation script for the "SubTotal", assuming the checkbox is named "SubOvr"
event.value = this.getField("HST").value;
event.rc = this.getField("SubOvr").isBoxChecked(0);
event.readonly = event.rc;
when the checkbox is checked, the user is allowed to enter a value, when it is unchecked, the field is set to read only, so the user cannot click into the subtotal, and the calculation sets the value of the field.
There are other methods for doing this that automatically detect when the user is trying to enter a value and then set a hidden checkbox value (or document variable) that does essentially the same thing. However this is more complicated.