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

Dividing 2 Fields

elcheque
Registered: Apr 7 2008
Posts: 13
Answered

I have a field (tot_liq_assets) that is the sum of 10 other fields. I have another field (adj_net_worth) that is inputted. I want to divide "tot_liq_assets" by "adj_net_worth" to get a percentage "conc_liq_assets". The problem is: if I use a simple field notation calculation, I get an error message every time I try to input a number into the 10 fields that are summed in "tot_liq_assets", The message is: The value entered does not match the format of the field [conc_liq_assets]. This seems to occur when nothing is inputted into "adj_net_worth". If "adj_net_worth" is inputted first, I get no error message. However the form is not designed to input "adj_net_worth" first.
 
I then searched the forum and found a script by gkaiseril as follows:
 
if (G1NumberofItems <> 0) then
G1Total / G1NumberofItems
else
null
endif
 
This seems like it should eliminate the error message, but I keep getting a syntax error on line 2.
 
Any help would be greatly appreciated.

My Product Information:
Acrobat Pro 9.4, Macintosh
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
That code uses the FormCalc language that's available for XFA forms created with LiveCycle Designer, not forms created with Acrobat. You'll have to use JavaScript, something like:

// Calculation script
(function () {

// Get field values as numbers
var numerator = +getField("tot_liq_assets").value;
var denominator = +getField("conc_liq_assests").value;

// Perform calculation
if (denominator !== 0){
event.value = numerator / denominator;
} else {
event.value = "";
}

})();


This code sets the field to blank if the denominator field is blank.
elcheque
Registered: Apr 7 2008
Posts: 13
George,

Thanks! the denominator was actually "adj_net_worth" but the script worked like a charm.