Copy link to clipboard
Copied
Hello! I have a form that has multiple calculations, and one thing I've been asked to do is to divide one field by another and show the result in a third field. This third field should round down to the nearest whole number. However if the nearest whole number is 0, the field should show 1 as the result. I've looked online for javascript to put in the Custom Calculation Script window, but nothing has worked so far. Can someone help me figure this out?
Lets say you have "Field A", "Field B" and "Field C", you can use this as custom calculation script of "Field C":
var a = Number(this.getField("Field A").value);
var b = Number(this.getField("Field B").value);
if(b != 0)
var x = Math.floor(a/b);
if(x==0)x=1;
event.value = (a&&b)?x:"";
Copy link to clipboard
Copied
Hi there
Hope you are doing well and sorry for the trouble.
The workflow that you are trying to achieve is possible using JavaScript. For more information please check the help pages listed below:
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html
https://acrobatusers.com/tutorials/javascript_console/
Regards
Amal
Copy link to clipboard
Copied
Thank you for posting the links, Amal!
Copy link to clipboard
Copied
Lets say you have "Field A", "Field B" and "Field C", you can use this as custom calculation script of "Field C":
var a = Number(this.getField("Field A").value);
var b = Number(this.getField("Field B").value);
if(b != 0)
var x = Math.floor(a/b);
if(x==0)x=1;
event.value = (a&&b)?x:"";
Copy link to clipboard
Copied
Nesa - Thank you so much!! This works perfectly and you laid it out in an easy to read and modify format! 🙂