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

Changing Text Field Color when filled in

CynthiaD
Registered: May 19 2007
Posts: 8

I have a text field overlayed on a set of lines on a form. I would like to put a format script in the field, which evaluates if there are any
contents, and if there are, sets the fillColor to white(thus hiding the lines), and if there are no contents, sets the fillColor to transparent (thus showing the lines).

It seems that this should be simple enough, but I don't have much experience with scripting. Thanks for the help!

Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
Put this script in Properties > Validate > Run custom validation script-----------------------------------------------------------------
if (getField(fieldName).value == "")
{
this.getField(fieldName).fillColor = color.transparent;
}
else
{
this.getField(fieldName).fillColor = color.white;
}
-----------------------------------------------------------------

;-)
CynthiaD
Registered: May 19 2007
Posts: 8
I tried it (of course changing fieldname to the actual name), but nothing happened. :(

What did I do wrong?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
If you are using Acrobat forms you either need to create a string variable with your field name or put the field name in quotes.

var fieldName = "My Field Name"; // establish field name to process
if (getField(fieldName).value == "")
{
this.getField(fieldName).fillColor = color.transparent;
}
else
{
this.getField(fieldName).fillColor = color.white;
}// or

if (getField("fieldName").value == "")
{
this.getField("fieldName").fillColor = color.transparent;
}
else
{
this.getField("fieldName").fillColor = color.white;
}// or

var oField = this.getField("My Field Name"); // get "My Field Name" object

if (oField.value == "") // test field object's value
{
oField.fillColor = color.transparent; // set field object's fill color
}
else
{
oField.fillColor = color.white; // set field object's fill color
}

George Kaiser

Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
gkaiseril wrote:
If you are using Acrobat ... or put the field name in quotes.
Oops !

;-))
MadMich
Registered: Aug 29 2007
Posts: 38
For some reason my modified script below is working randomly! it's supposed to change color when 3 or 6 is entered into the text field.
Please help!

var oField = this.getField("Text1"); // get "My Field Name" object

if (oField.value == "3") // test field object's value
{
oField.fillColor = color.yellow; // set field object's fill color

}else if (oField.value == "6") // test field object's value
{
oField.fillColor = color.red; // set field object's fill color

}else
{
oField.fillColor = color.white; // set field object's fill color
}
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
If "Text1" is the field that this script is attached to, try this:

// Validate script for text field
switch (event.value) {
case "3":
event.target.fillColor = color.yellow;
break;
case "6":
event.target.fillColor = color.red;
break;
default:
event.target.fillColor = color.white;
break;
}