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

Validate a field

tdunn
Registered: Aug 3 2007
Posts: 14

I need to validate a field to null if it is zero but I am a javascript dummy. What exactly would I need to enter to get this to work?

My Product Information:
Acrobat Pro 7.0.7, Windows
lsutton
Expert
Registered: Nov 15 2005
Posts: 51
If you are looking to manually verify the existence of data in a field you can use the "if" in JavaScript:


if(this.rawValue=="" || this.rawValue == null)
xfa.host.messageBox("You did not enter the data in TextField1");
AndrewAlb
Registered: Aug 16 2007
Posts: 97
I too an interested in this - I have a code that interacts with two fields - and you can only put data in one of the fields. So upon entering field B adobe checks to see if field A is null - if it is not an alert pops up and says "You can only have data in one field, shall I erase the data in the other field". Now, I can just put an empty string (value = "") but then that is not the same thing as null and so my code breaks down and even when the cell is empty (contains a zero length string "") the error message still runs. So I need to make it null and not just "" - how can I do this?
(by the way if it matters, it is a number field). Here is the code:

var FedDol = this.getField("IncomeTaxWitheldFederalPercent");

//Check to see if the other field is null
if (FedDol.value != null)

//If it is null run the alert
var nRslt = app.alert("Only one federal value may be entered - either dollars or percentage.\n\n" + "Shall I erase the percentage value in order for you to add a dollar amount?",2,2,"Warning");

//If the users selects 'yes' make the other field null
if(nRslt == 4)
FedDol.rawvalue == null;

Andrew D. Albrecht, MS
Solutions Developer
ING USFS

lsutton
Expert
Registered: Nov 15 2005
Posts: 51
If I understand correctly you are looking to do two comparisons?

In the JavaScript world you will need an AND or an OR. && = AND, || = OR.if(this.rawValue=="" || this.rawValue == null)

This translates to:

"If the value of this field is blank OR has a null value"

So two things I usually do, check for the value of null or blank, but also "trim" the value to ensure that the leading and trailing blanks are ignored / removed from the field.