Hi,
I've tried very hard to figure out where I'm going wrong by reading all the posts I could find. I've been semi-successful but have hit a stumbling block.
I'm doing this in Adobe Acrobat 7.0. I have a form that clients can either fill out electronically or by hand, they get the choice so it's vital that 0.00 does not show up in the field.
To calculate product cost by product quantity and hide the 0.00 I've put this code in the total product cost field and it works perfectly at hiding the 0.00 for each product
var f = this.getField("Product5Cost");
var g = this.getField("Product5Qty");
if (g.value!=0)
event.value= f.value * g.value
else
event.value= ""
The problem comes in here - there's a calculated field at the bottom of the total product cost field column that sums up a grand total of all individual products costs . I've used "Value is the sum of" and selected appropriate fields and put the following in the Validation area
if (event.value ==0) event.value=""; This just won't work for me for some reason. If the only way to do this is write a complex java script that has to sum 12 products AND get the event.value part in there could somebody get me started on that? All I know about Javascript I've learned in the last 2 days! Thanks very much.
The first order of business is to be certain you use hierarchical names for your field objects. That will make calculations much easier. If I have a column of fields named amount.0, amount.1, amount.2, etc. then I can use the parent name (amount) in my calculation formula.
Summing a column using the field names suggested above would be:
var f = this.getField("amount");
var a = f.getArray();
var sum = 0;
for (i =0; i < a.length; i++)
sum += a[i].value;
if (sum !=0)
event.value = sum;
else
event.value = "";
You can get a lot of JavaScript tips by downloading my ebook: 101FormseTips.pdf from here on Acrobat Users. There's a link to the file on the home page.
Hope this helps.
ted
The author of numerous books on Acrobat, Photoshop, Illustrator and the Adobe Creative Suite, and an international speaker on Adobe Acrobat, Ted Padova is a well-known PDF guru.