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

change the background if a checkbox is checked

wmbb
Registered: May 24 2010
Posts: 8

I would like to color the background of a textbox red if a checkbox is checked but I can't get the code working.
Can somebody help me ?

code:

var f = this.getField("urgent");
var ff = this.getField("urglabel");

if (f.isBoxChecked(0)) then {
ff.fillColor = color.red;
}
else {
ff.filColor = color.white;
}

try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
1. There's no such thing as "then" in JS. It's not VB. Remove it.
2. You have a typo in this line:
ff.filColor = color.white;
It should be:
ff.fillColor = color.white;
3. Where did you place this code?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

wmbb
Registered: May 24 2010
Posts: 8
I'm using cenopdf to create fillable PDF files.
This code is used in a mouse-up event from the checkbox.
You can use javascript in it.
I'll change those items this evening and let you know if that was the problem.
wmbb
Registered: May 24 2010
Posts: 8
Fine, that was the problem.
If you're programming in different languages, you easily miss this kind of errors.

Thanks for your help.
nmjfaulkner
Registered: May 24 2010
Posts: 29
I am trying to follow this to see if I can use something similar. I am using LiveCycle Designer ES2 9.0, have a few questions:

I do not get what 'this.getField' is (there is no getField syntax I can find in the Adobe scripting reference, but I do see it as a java code element)

what the "urgent" and "urglabel" are (I am assuming "urgent" is the name of the checkbox and "urglabel" is the text box you are looking to color red)

and why the need for variable passing at all?

I wouldn't mind changing the color of a caption for a textfield based on the user selercting NO from a radio group...