Skip to main content
New Participant
September 5, 2017
Question

Remove red highlight after checkbox is checked, Acrobat Pro DC

  • September 5, 2017
  • 1 reply
  • 1702 views

I have a form with required checkboxes highlighted in red.

I have successfully added javascript to remove this border from my text fields once filled in, by running a custom validation script, but this script does not work for checkboxes.
Can anyone help me with a script to simply remove the red border of a checkbox, once checked? I am new to javascript, so a script and location would be wonderful. Thanks in advance.

This topic has been closed for replies.

1 reply

Thom Parker
Adobe Expert
November 1, 2017

Checkboxes are particularly difficult to program like a text field.  First off, there are only two values, on and off, so how do you validate that? Second, while a checkbox has a validation and calculation script, they are not accessible from the Acrobat UI. 

So I'm assuming that this if for something like "I agree to the terms" check box?  You could use the mouse up event to check the value of the checkbox.

event.target.borderColor = (event.target.value == "Yes")?color.black:color.red;

But the "mouse up" only catches mouse and keyboard events.  If that is all you need, then use it. But if you need the form setup correctly when auto filled, then you need to use the validate or format event.  To use one of these you'll need to set the script programmatically from the JavaScript Console Window. Like this

this.getField("MyCheck").setAction("Validate","event.willCommit || (event.target.borderColor = (event.value == \"Yes\")?color.black:color.red);");

Where "MyCheck" is the name of your checkbox field

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