I am using a Custom Script to total a column of figures.
-------------------------------------------
var f0=this.getField("txAmount0").value;
var f1=this.getField("txAmount1").value;
var f2=this.getField("txAmount2").value;
var f3=this.getField("txAmount3").value;
event.value=f0 + f1 + f2 + f3;
if (event.value==0)
event.value="";
----------------------------------------------
This works correctly unless there is an empty field between two fields with entries, then it stops adding to itself (to increase the total) and starts to tack on the new entries to the end of the old!
For example: if I put the figure 10 into the first three fields. the total is correctly displayed as 30.
However, if I only put the number 10 into fields 1 and 3 (leaving field 2 empty) the total displays like this : 1,010.00 and continues to add on each entry.
If I go back and put a number into the blank field, even a zero, the total recalculates and displays correctly.
So there is obviously something wrong with my calculation script. i have tried pretty well every variation I can think of to get it to work, but no luck.
I'm sure there is a simple solution, but it's eluding me!
I need to have to 0.00 default display hidden because the form is sometimes printed to be filled out manually, so the 0.00 spoilse the total field.
I'd be grateful for any help... even if I have to say DOH! when the answer is revealed :-)
Version is Acrobat 9 Pro Extended 9.4.6
Thank you
The solution is simple: force the script to treat the blank values as a number (0), by placing a Number() constructor around them, or simply a "+" before them (another use for it!), like so:
var f0 = +this.getField("txAmount0").value;
var f1 = +this.getField("txAmount1").value;
var f2 = +this.getField("txAmount2").value;
var f3 = +this.getField("txAmount3").value;
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com