Skip to main content
August 20, 2019
Question

change fill color of a field depending on checkbox

  • August 20, 2019
  • 1 reply
  • 4078 views

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

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
August 21, 2019

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;

Participant
March 26, 2020

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?

Thom Parker
Community Expert
Community Expert
March 26, 2020

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.  

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often