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

Validating if a field is blank

ccs717
Registered: Aug 18 2006
Posts: 20
Answered

Hello,

In my form I have two text fields - "text3" and "text4." I want to add a visual cue that if either field contains data, the other one turns red until it too has data. My calculation script for "text3" looks like:

if( (this.getField("text4").value != null) && (this.getField("text4").value.length > 0) && (this.getField("text3").value.length == 0) )
event.target.fillColor = ["RGB",1,0.5,0.5]
else
event.target.fillColor = ["RGB",1,1,1]

This script works perfect...except if one of the field contains NUMBER characters ONLY.

Any thoughts as to why this would be or how to correct it?

Many thanks.

My Product Information:
Acrobat Pro 8.1.2, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You should never check a field value against null, since a field value will never be null. It is not the cause of your problem, however.

In this case, you should look at the "valueAsString" field property, as opposed to the "value" property. The code can be simplified to:

// If text4 is is not empty but text 3 is...if (getField("text4").valueAsString && !getField("text3").valueAsString) {

But I would suggest not using the Calculate event for this. Something like it really belongs in the Validate event of both fields.

George
ccs717
Registered: Aug 18 2006
Posts: 20
Thank you George. The script I posted was based on one found elsewhere on the AUC site.