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

text field validation

chrisamp
Registered: Jan 21 2009
Posts: 11
Answered

Hi,

I have a budget form with a row of 5 number ($) text fields. The 5th field's value can't exceed the total of the four fields before it. if it does i want it to return an error msg and reset the value of the field to 0.

So i figured this script needs to be in "Run a custom validation script" of field name "cashe_e" and it would be something like this:

var a = this.getField("cash_a");
var b = this.getField("cash_b");
var c = this.getField("cash_c");
var d = this.getField("cash_d");
var e = this.getField("cash_e");

if (e > (a+b+c+d)) {
app.alert("The request cannot be more than the total cash expended amount in this category for the current event");
}

Please help!!

Thank You!

My Product Information:
Acrobat Pro 8.0, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You could try doing it that way, but when doing numerical addition you should explicitly convert each field value to a number before doing the addition since a blank field value will be considered a string and you'll can get string concatenation instead of addition. You should also add validation code to each of the other fields if any of the "a" through "d" fields can get changed after an entry is made in the "e" field.

The custom validation code for the "e" field might look something like:

(function () { // Get field values, as numbersvar a = +getField("cash_a");var b = +getField("cash_b");var c = +getField("cash_c");var d = +getField("cash_d"); // Get the value the user entered into this field, as a numbervar e = +event.value; if (e > (a+b+c+d)) { // Alert userapp.alert("The request cannot be more than the total cash expended amount in this category for the current event"); // Set value of field to zeroevent.value = 0;} })();

This code assumes the fields have a format category of Number.

George
chrisamp
Registered: Jan 21 2009
Posts: 11
THANK YOU!!
works perfectly!