Skip to main content
New Participant
May 15, 2018
Answered

How to have a blank calculated field?

  • May 15, 2018
  • 1 reply
  • 6555 views

I'm creating a PO form and using the product calculation to automatically calculate Cost per Unit x Units. While the calculation works, I don't want their to be "0.00" always visible. Is there any way to make the default view of a calculated field to be blank until numbers are input into the other fields? Screenshot attached.

Correct answer Thom Parker

Hm, that doesn't seem to have done what I'd like it to do. My intent is for the product calculation (Total) to only appear when values have been entered into the related Cost Per Unit and Unit fields. I'm still seeing "0.00" with the custom format script and the product calculation. If I want to send this out to vendors, I don't want a bunch of "0.00"s down the page when they aren't necessary. Trying to make as much sense as I can. Just started messing around with Forms and such. Thank you!


Try this:

event.value = (event.value != 0)?util.printf("%,0.2f",event.value):"";

The problem with the first script is that the value is not automatically a number. So an explicit test is necessary.

1 reply

Thom Parker
Community Expert
May 15, 2018

Yes, don't use the default Number formatting.  Create a custom format option instead.

Here's a Format Script for your total field

event.value = event.value?util.printf("%,0.2f",event.value):"";

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
beng312Author
New Participant
May 15, 2018

Thom,

Thanks for responding! Do I keep the product calculation or do I replace that with something else?

beng312Author
New Participant
May 15, 2018

The calculation is fine, leave it unchanged.  All that is necessary is to modify the formatting.  The formatting script only affects how the value is displayed to the user. It does not affect the actual value of the field.


Hm, that doesn't seem to have done what I'd like it to do. My intent is for the product calculation (Total) to only appear when values have been entered into the related Cost Per Unit and Unit fields. I'm still seeing "0.00" with the custom format script and the product calculation. If I want to send this out to vendors, I don't want a bunch of "0.00"s down the page when they aren't necessary. Trying to make as much sense as I can. Just started messing around with Forms and such. Thank you!