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

Can formulas be called form functions or global variables?

David Dunn
Registered: Oct 28 2010
Posts: 116
Answered

Can a formula be placed in a function or global variable and then employed in a field's custom calculation? If so, I would appreciate it if someone would please provide or give a reference to a short sample. I've tried unsuccessfully.

David D

My Product Information:
Acrobat Pro 9.4, Windows
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
Accepted Answer
Which kind of formulas are you talking about? Do you mean for calculating a field's value?
If so, of course it can. You just need to place them in a function and then call that function from the field's Calculate event.
For example, let's say you have a document-level folder that sums up 20 fields:

function sum20Fields() {
var total = 0;
for (i=0; i<20; i++) {
total+=this.getField("Field"+i).value;
}
return total;
}

Then you can call this function from the field's Calculate event like so:

event.value = sum20Fields();

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

David Dunn
Registered: Oct 28 2010
Posts: 116
Yes, for calculating a field's value, to be called in another formula inside a custom calculation, which you answered.

What reference can I look to for a detailed explanation of the elements of this portion of your sample formula:

for (i=0; i<20; i++)

David D

try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
That's general JS syntax. You can read the reference for it here, for example:
https://developer.mozilla.org/en/JavaScript/Reference
Or follow this tutorial:
http://w3schools.com/js/default.asp

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

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Functions can be placed in any action on a form, at the document level of a form, or in an application level folder. Depending upon where the JS code is located and written will determine the scope of the function.

If you need more information about Acrobat JavaScript, access the free documentation from Adobe's developer site. More information about JavaScript is available through the Mozilla Developer site.

George Kaiser