These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need help hiding a field if numerical value = 0

tetrylone
Registered: Nov 29 2011
Posts: 5
Answered

Hi there,
 
I am trying to hide a text field if the dollar value of that field is equal to zero. The field should display if the value is greater than $.01. Is there any way to do this with a text field format script or otherwise? Id so, how? Using Acrobat X on a pc BTW.
 
Thanks in advance!

Thanks!

My Product Information:
Acrobat Pro 10.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Is this a calculated field? If so, are you using a custom calculate script or are you using one of the built-in methods?
tetrylone
Registered: Nov 29 2011
Posts: 5
Yes to both. Calculated and built-in.

Thanks!

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
In that case you can add a custom Validate script for the field:

// Blank the field if it calculates to zero
if (+event.value === 0) event.value = "";
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
George's script will reset the value of the field. If you want to hide it, use this code instead:
event.target.display = (+event.value === 0) ? display.hidden : display.visible;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

tetrylone
Registered: Nov 29 2011
Posts: 5
try67-

That totally worked but I lost my formatting for $. Can I modify that script to format of $0.00?

Thanks!

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Be aware that hiding a field will not exclude it from use in a calculation.

If you are going to use this field in a calculation, then you need to zero it out or set it to a null value.

It is possible to have a field with a currency symbol show a null, but you need to use some JavaScript to change the numeric format for when it has non-zero value or a numeric value.

Also any validation script requires that a calculation or form reset occur before you will see the affect of a validation script.

George Kaiser