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

Validation Script: One Fields Equals the Sum of Other Fields

commonsage
Registered: Mar 8 2011
Posts: 4
Answered

I want to write a script that validates the equality of one field called "Cash 2010" with the sum of 6 other number fields. If the number entered into the "Cash 2010" field does NOT equal the sum of the other 6 fields, then I want a warning message to appear stating they must be reconciled.
 
I tried to write a script based on other forum postings but it does not work. Can you tell me how to rewrite this script and make it work?
  
(function () { // Get field values, as numbersvar a = +getField("1 to 999 Total");var b = +getField("1000 to 4999 Total");var c = +getField("5000 to 24999 Total");var d = +getField("25000 to 49999 Total");var e = +getField("50000 to 99999 Total");var f = +getField("100000 Total"); // Get the value the user entered into this field, as a numbervar g = +event.value(“Cash 2010”); if (g != (a + b + c + d + e + f)) { // Alert userapp.alert("Cash Donations in this column must be equal to the total donations listed above in the ‘Number of Donors and Gift Size Last FY’ row above. Remember to include foundation and government grants in both sections."); // Set value of field to zeroevent.value = 0;} })();

Paul

My Product Information:
Acrobat Pro Extended 9.4.2, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
Change this line:

// Get the value the user entered into this field, as a number
var g = +event.value(“Cash 2010”);


to this:


var g = +event.value;
commonsage
Registered: Mar 8 2011
Posts: 4
Thanks George. Works perfectly now.

Paul