Copy link to clipboard
Copied
Hello,
I am new to Acrobat Javascript and I would like to get some help on this:
I have a pdf form where I have a Volume "VF" [liter] in one field and a Flow "Q" [liter/minute] in another field. In the third field I would like the calculation of Emptying time in seconds: (VF/Q)*60
Now, I manage to get the formula right, but as you start to fill in the other fields, the Q field is equal to zero so you get a message that the stated value do not match the field format. I understand this has something to do with the denominator is 0. I googled and tried the Javascript below but it doesnt work. What is wrong?
(all fields have the same format.)
// Custom calculation script(function () { // Get field values as numbersvar v1 = +getField("VF").value;var v2 = +getField("Q").value; // Perform calculation if denominator is not zero (or blank)if (v2 !== 0) {event.value = ( v1 / v2 ) * 60;} else {event.value = "";} })();
Try != not !== . I didn't know !== even existed until just now And it doesn't seem quite right though it looks good in theory. If still no good, any message in console?
Copy link to clipboard
Copied
Don't put the code in one line.
// Custom calculation script
(function () {
// Get field values as numbers
var v1 = +getField("VF").value;
var v2 = +getField("Q").value;
// Perform calculation if denominator is not zero (or blank)
if (v2 != 0) {event.value = ( v1 / v2 ) * 60;} else {event.value = "";}
})();
Copy link to clipboard
Copied
Try != not !== . I didn't know !== even existed until just now And it doesn't seem quite right though it looks good in theory. If still no good, any message in console?
Copy link to clipboard
Copied
Thanks it works now!
Copy link to clipboard
Copied
There's a really helpful explanation of comparison operators here...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now