change fill color of a field depending on checkbox
Copy link to clipboard
Copied
hello,
I have a checkbox and would like to change the color of an other field depending on activating the checkbox.
the other field isn't an empty field, there is already text in it. is it possible only to change the background color of this field if the checkbox is activated?
can you please help me
Copy link to clipboard
Copied
Sure. As the Mouse Up event of the check-box field you can use something like this:
this.getField("Text1").fillColor = (event.target.value=="Off") ? color.transparent : color.yellow;
Copy link to clipboard
Copied
For me this works great on the form iteself, but I am passing data to the form from an outside program. The Mouse Up event doesn't work. The check boxes do come out as checked when the PDF is generated, but not the Mouse Up javascript fill colors. Is there another method that might work?
Copy link to clipboard
Copied
How is the data loaded? If it is from an FDF file, then the FDF can contain a script to setup the correct color values.
If the form is open in Acrobat when the data is loaded, then you can use a script that is triggered by a data change. The calculate event is an obvious choice since it's triggered any time anything changes, any calculation script on any field will work for this. But you have to be careful for the same reason.
If the data is merged into the PDF external to Acrobat, then you need a document level script that sets the colors when the PDF is opened in Acrobat.
Use the Acrobat JavaScript Reference early and often