Copy link to clipboard
Copied
I have a custom calculation script in a form field that works when I put nthe script in and close and enter data but after the form is cleared it will not work again unless I go back in and put the custom calculation script in again. I have several custom calculation scripts in the form that are working fine, so I am not sure what I have done wrong?
event.value = Number(this.getField("Remaining Balance 3").valueAsString) / Number(this.getField("Divide by 2").valueAsString);
Copy link to clipboard
Copied
Please check the console window for errors (Ctrl-J).
There is one error in this code. There is a possible divide by zero condition that is not accounted for, as well as NaN conditions.
Change the script to this. But please check the console first.
var cDivisor = this.getField("Divide by 2").valueAsString;
if(cDivisor && !isNaN(cDivisor) && (Number(cDivisor) > 0))
{ // Proceed with calculation
event.value = Number(this.getField("Remaining Balance 3").valueAsString)/Number(cDivisor );
}
An NaN condition (Not a Number) is when text does not automatically convert to a number. Usually this condition is obvious, but a more subtle case is when a written number contains commas. Commas do not convert.
Copy link to clipboard
Copied
Unfortunately I my version of Adobe does not support using the Ctrl-J command so I pasted this as the script and it is saying Syntaxerror: missing } in compound statement 1: at line 2
Copy link to clipboard
Copied
That error does not match the script, so something is off. Perhaps you missed copying the final closing bracket?
Regardless, all Acrobat versions have a console window, even if the button for getting to it is missing. Go to the Acrobat Preferences and find the "JavaScript" category. Select the option that displays the console(or debugger) on an error.
Copy link to clipboard
Copied
Thanks, I will give this a shot!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now