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

Validation Script: Alert Message Appears Always instead of Conditionally

commonsage
Registered: Mar 8 2011
Posts: 4
Answered

I want an alert message to appear when one number field does not equal the sum of 6 other number fields. Right now the following script makes the warning message appear whether or not the sum equals the entry into the "Cash 2010" number field. What do I need to do to make the warning message disappear when the sum field does equal the sum?
 
(function () {
// Get field values, as numbers
var 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 number
var g = +event.value;
if (g != (a+b+c+d+e+f)) {
// Alert user
app.alert("Cash Donations in the Cash Donation 2010 field must be equal to the total donations listed above in the 'Total Amount' row for ‘Number of Donors and Gift Size Last FY.’ Remember to include foundation and government grants in both sections.");
} })();

Paul

My Product Information:
Acrobat Pro Extended 9.4.2, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Can you give exact examples of the field values in each of the fields in question when you think they should be equal? For example:

a = 1
b = 2
c = 3
d = 4
e = 5
f = 6
g = 21

You may need to round the sum and the "g" value to the same precision before doing the comparison.
commonsage
Registered: Mar 8 2011
Posts: 4
I've entered a variety of values into var a-f fields. For example, if I put a 5 into each category and then put 30 in the g field, it still gives the alert message. Does it matter that I have both fields formatted as numbers with currency symbols?

What would the code be to round the values to the same precision?

Paul

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
The problem is the code isn't getting the value of the fields, so the code should be:

  1. (function () {
  2.  
  3. // Get field values, as numbers
  4. var a = +getField("1 to 999 Total").value;
  5. var b = +getField("1000 to 4999 Total").value;
  6. var c = +getField("5000 to 24999 Total").value;
  7. var d = +getField("25000 to 49999 Total").value;
  8. var e = +getField("50000 to 99999 Total").value;
  9. var f = +getField("100000 Total").value;
  10.  
  11. // Get the value the user entered into this field, as a number
  12. var g = +event.value;
  13.  
  14. if (g != (a+b+c+d+e+f)) {
  15. // Alert user
  16. app.alert("Cash Donations in the Cash Donation 2010 field must be equal to the total donations listed above in the 'Total Amount' row for ‘Number of Donors and Gift Size Last FY.’ Remember to include foundation and government grants in both sections.");
  17. }
  18.  
  19. })();