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

Changing the color of a form field using Javascript & If/Then?

scribbleit
Registered: Jul 21 2010
Posts: 21

I need help with Javascript. I know nothing about it and searching the web is giving me a headache! What I am trying to do seems simple enough, but I have no idea how to make it work.

I am creating a pdf form that will be used on a Tablet by my client. There will be a series of questions that he will use a Stylus pen to choose an answer. Most questions will be yes or no.

What I would like to do is create a form that does this. If he chooses "yes", then the question turns "green".
If he chooses "no", then the question turns "red".

I have learned that if the question is part of the text in the pdf, then this type of operation can't be done. What if I create a form and put each individual question into a form field. Then, based on the action of clicking "yes" or "no", another action will happen that will change the color of the "question" form field.

Will this work using Javascript?

And, if it will work, can I cause multiple form fields to turn red or green based on that same answer? In other words, some of the questions will have a blank that he will type in more information to explain the yes or no answer. Can I use the "yes" or "no" action to not only turn the "question" red or green, but to additionally turn another form field red or green?

This just seem so simple, but I cannot find the answer. Oh, BTW, the original pdf will be designed as a table in InDesign.

Please offer any suggestions and/or solutions.

THANK YOU!!!

My Product Information:
Acrobat Pro 8.1.7, Macintosh
StevenD
Registered: Oct 6 2006
Posts: 368
There may be other ways but here is one way. You could try to put some code like below into a custom calculation script of the text field you want the color of the text to change.

//Get the field named "Rad.YesNo". Change the name of the field to match your naming convention
var myRad = getField("Rad.YesNo");

//If the Yes radio button is checked then make the color of the text black.
if(myRad.value == "Yes")
{
getField("Txt.Wahoo2").textColor = color.black;
}

//If the No radio button is checked then make the color of the text red.
if(myRad.value == "No")
{
getField("Txt.Wahoo2").textColor = color.red;
}

Make sure each radio button in the group has a value assigned to it. You assign values to radio buttons and check boxes in the Options tab of the field properties dialog.

StevenD

scribbleit
Registered: Jul 21 2010
Posts: 21
thanks StevenD,

I am trying what you said, but it is not working. Since I know next to nothing about the scripting, it's hard for me to tell exactly what I need to change from your example to my working file. I tried changing "Txt.Wahoo2" to "water" like in my doc. I also named the radio buttons accordingly. I'm confused about the myRad part of your example. In my document, is there something I need to change? When I try to preview the form, I have 2 radio buttons and they both click black. I'm not sure how to tie the to each other so that if you accidentally check yes and want to change the answer to no, then how do you tell it to only accept one answer or the other? ugh!
SymmetryMedical
Registered: Apr 21 2010
Posts: 26
I'm no expert so if I'm stating the obvious or giving bad advice please ignore/correct me, but to group the radio buttons together give them the same name, it's a group name rather than an individual button name, and it should reflect this in the Fields section. e.g. Radio1 would be the group, and within that you'd have a radio button with value Yes, one with No, etc.

I can't help with the rest of the code but it's a similar problem to mine so I'll be watching this thread with interest.