Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hide Calculated unused $0.00 form fields.

New Here ,
Mar 22, 2019 Mar 22, 2019

Hello, I have an excel spreadsheet that I have turned into a form with Adobe Acrobat Pro that has a qty field, a price field and a total field, among others. I have set the total field to automatically calculate to the product of the Qty field and price field, which works fine. The issue is that by default it displays a zero (or actually, $0.00, since I have it formatted to price), and so if people print out the form to fill it out manually, they have to cross out the zero.

Is custom javascript the only way to get the field to be conditionally hidden or non-printable? If not, can you tell me a better method? If so, can you point me to an example of this that works? I can provide screenshots if necessary.

TOPICS
PDF forms
14.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Mar 22, 2019 Mar 22, 2019

As the custom validation script of the field enter this:

if (event.value==0) event.value = "";

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2019 Mar 22, 2019

As the custom validation script of the field enter this:

if (event.value==0) event.value = "";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2019 Mar 22, 2019

PS. In the future you'll be better off posting questions about Acrobat in the Acrobat forums, like this one: PDF Forms

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 17, 2019 Sep 17, 2019
I tried this answer but in order to add a custom validation script it deletes your Value is... " " of the following fields statement. Is there a way to add both statements?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2025 Jan 24, 2025

I cannot get any of these formulas to work.  The 0 still shows up no matter what.  I've removed the currency symbol and still have the issue

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2025 Jan 24, 2025

Post an example PDF of your attempt to get this to work. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2025 Jan 24, 2025

So I finally got it working.  Pretty ridiculous but if you put the calculation in before adding the script it will not work.  I had to add the script first, and then the formula and then the format for $.  Any other order results in the 0 showing on the form. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2025 Jan 24, 2025

So did you read the posted article?  It is not a good idea to use both built in formatting and a script to adjust formatting. But if you do not provide us with the details of what you are trying to do we can not help you to do it correctly.  And it does not seem you are doing it correctly, which can lead to undesired results. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2025 Jan 24, 2025

Ok I see that now.  I had it working but now when I type anything into an unrelated field, it changes all 8 calculated cells to $0.00

 

How would you suggest to make a formula for my total cost cell.  Basically it is a quote form, and the final text field in each row is a calculated product of two other cells.  I want it to show the $ and two decimal places but I also want it to remain blank if the value is $0.00.  The quote form is 8 rows, but if you just put values in the first row and print it, everything else remains blank.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2025 Jan 24, 2025

So first, read this article:

https://www.pdfscripting.com/public/How-to-set-000-value-to-blank.cfm

Use the Format script example for your form.

 

If there are still issues, post your form with the code you think should be working and we'll take a look at it. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 19, 2025 Nov 19, 2025
LATEST

I used the instructions on this page and it worked!

Right-click the calculation field you want to be blank and select Properties. Under the Format tab select Custom from the drop down. 

 

1) Click Edit for "Custom Format Script" and paste in the following script:

if((event.value == 0) || isNaN(event.value) || (event.value == Infinity))
	event.value = "";
else
	event.value = util.printf("$%,0.2f",event.value);

 

2) Now click Edit for "Custom Keystroke Script" and paste in the following script:

if(event.willCommit && (event.value == 0))
    event.value = "";

 

Replicate this process for each field you want to show blank.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 10, 2020 Feb 10, 2020

This isn't working for me. I also have my field formatted to dollar figure. My field's name is ClosingBalance.

I'm inserting 

if (event.value==0) event.value = "";

in the "Run custom validation script" box. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2020 Feb 10, 2020

Post your question to a new thread

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2020 Mar 26, 2020

Were you able to get the custom validation script to work with the field being formated with the currency symbol ($0.00)? I am having the same trouble. I can get it to  work if I remove the currency symbol. I don't know much about JavaScript.

 

Does something else need to be included in the script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2020 Mar 26, 2020

Do you have a default value set as 0 for the field? That was my issue. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2020 Mar 26, 2020

I do not. The only properties I have are:

 

Custom validation script, if (event.value==0) event.value="";

Calculation is product of, QTY Row 1, UNIT PRICE R1

 

The custom validation script will work as long as I change the currency symbol to NONE, but really need this column to be a currency and not just numeric with decimal.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2020 Mar 26, 2020

So on my Options tab, there is Default Value. Make sure there's no value in there. 

 

The rest "should" work. Decimal places 2, currency symbol. 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 03, 2020 Aug 03, 2020

This is close to the problem I'm having. I have estimated days of inventory on hand (Text53)  as a calculation. Quantity on Hand (Text52) divided by Daily Usage (Text51). So in the simplified field notation I have: Text52/Text51. Only problem is I get errors when I set properties on Text53 to number. I get Java errors. (The Value entered does not match the format of the field [ Text53] So I leave it at none but then it keeps putting NaN in the cell if a number was entered and then cleared. When I clear the form the NaN stays there. I'd like it to go to blank if anything or 0.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 03, 2020 Aug 03, 2020

You will get NaN when you divide by zero.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 03, 2020 Aug 03, 2020

So how do you get it display blank instead of NaN?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 03, 2020 Aug 03, 2020

Use Javascript for the calculation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 03, 2020 Aug 03, 2020

Thank you. I'm still unclear. In the Calculate form properties? Currently is is in simplified field notation: Text52/Text 51. You are saying to use the custom calculation script instead? And what would that Java look like?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 03, 2020 Aug 03, 2020

First, you've written that the name of the divisor field is "Text 51". Is this correct? if it is, then the simplified field notation will not work as written anyway. It doesn't like spaces in field name. 

Here's a calculation script that sets the field to blank if  

 

var nDivisor = Number(this.getField("Text 51").value);

if(nDivisor == 0)

  event.value = "";

else

  event.value = this.getField("Text 52").value/nDivisor;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2020 Aug 09, 2020

Here's an article that discusses this topic in detail:

https://www.pdfscripting.com/public/How-to-set-000-value-to-blank.cfm

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2022 Sep 20, 2022

Type this script into the DEFAULT VALUE box on the OPTION tab (not the RUN CUSTOM VALIDATION SCRIPT on the VALIDATE tab) .  This fixed the issue for me.

 if (event.value==0) event.value = ""

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines