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

Removing zeros from pdf document

pappyjack
Registered: Jul 8 2010
Posts: 7
Answered

I purchased "PDF FORMS BIBLE" bye Ted Pardova. This book is extremely helpful, but I am having a problem removing "0" from my document so it appears blank.

I am adding a column of 7 cells bye using the the following JavaScript in the "Simplified Field Notation" for the calculation;

MILESRow1_0 + MILESRow1_1 + MILESRow1_2 + MILESRow1_3 + MILESRow1_4 + MILESRow1_5 + MILESRow1_6

Then in the format tab, I used a custom format.

In the Custom Format Script I used the PDF Bible reference;

event.rc = /\d*/.test(event.change);

And then in the Custom Keystroke Script I used;

event.value =event.value?event.value: "";

Now, I had hoped this would work but it does not. Any suggestions? Thanks for any help you can give me.

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You can also use the code in the custom validation script.

George Kaiser

pappyjack
Registered: Jul 8 2010
Posts: 7
I did not understand the previous advice.

Ok, here is my dilema. I am a novice with JavaScript.
I am trying to make a voucher for travel and I do not want all the zeros in the form.
I have a table with 9 columns in it. Each column has 7 rows. The first column is titled "Miles", the second is "Mileage", the third is "Public transportation", next is "lodging", next "lodging tax", next "MIE", next "parking", and finally "other". Below each column is a sub total for each. I titled them Sub.0, Sub.1 etc...
Now the JavaScript I have inserted for each column sub total is:
var f = this.getField("MILES1");
var g = this.getField("MILES2");
var h = this.getField("MILES3");
var i = this.getField("MILES4");
var j = this.getField("MILES5");
var k = this.getField("MILES6");
var l = this.getField("MILES7");

if (f.value !=0)
event.value = f.value + g.value + h.value + i.value + j.value + k.value + l.value + m.value
else
event.value =""

Now this works to remove the zeros for each sub total.

Then I have a total voucher cell and I use the following JavaScript:

var f = this.getField("Sub.0");
var g = this.getField("Sub.1");
var h = this.getField("Sub.2");
var i = this.getField("Sub.3");
var j = this.getField("Sub.4");
var k = this.getField("Sub.5");
var l = this.getField("Sub.6");
var m = this.getField("Sub.7");

if (f.value !=0)
event.value = f.value + g.value + h.value + i.value + j.value + k.value + l.value + m.value
else
event.value =""

This also works to remove the zero, but when I put any amounts in the upper columns, the result adds about 10000.00 for some reason, and I cannot figure out why. I use the debugger, but I am still novice enough not to see the problem. Any help with my JavaScript would be helpful and greatly appreciated.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Each text flied has a 'Validation' property and one of the options is a JavaScript, one can place the code:
// if field value is zero display a null stringif (event.value == 0) event.value = '';

in the JavaScript option. This code will suppress a zero result no matter which calculation option one chooses.

JavaScirpt stores numbers in a format different than text, but numbers can also be stored or treated like text and are then in a different format than a number.

The '+' is the arithmetic addition operator and the text string concatenation operator. And how the '+' operator works depends upon what JavaScript thinks the values being processed are numbers (addition), text string (concatenation), or a combination of number and text string (concatenation). So if one wants the addition operation, one has to force all values to numbers using the 'Number(nValue)' constrictor.

A null string is a character string, but if constricted to a number it will be treated as zero. So any null string in a custom calculation where one is trying to add numbers will not be added but concatenated to the value.

But you could also use the other 2 methods for a calculation and those 2 methods will restrict the calculation to only numbers and with the validation script to suppress zero, have the problem solved.

See [url=https://acrobat.com/#d=BTBoKOwsJb0KdpT-*8SZqw]Sum vs. Plus[/url] for an example of how a null can change an addition process.

George Kaiser

pappyjack
Registered: Jul 8 2010
Posts: 7
Thanks!!! That worked!

If ever you find yourself in the Dallas area, send me an email and I will treat you to some excellent Tex-Mex!
ktboundary
Registered: Jul 10 2011
Posts: 1
George, thanks so much! I don't know anything about JavaScript, and my form now works as intended.