Skip to main content
Inspiring
Sep 22, 2025 4:53 AM UTC
Answered

Show/Hide Checkbox with Color & Style Based on Text Field Value

Hi, I have a text field and a hidden checkbox named 'Check Box1', what I need is when user writes 'Yes' in text field, checkbox shows and border and text color should be green and it should be checked with checkmark, if user writes 'No' then it should be red color and cross instead of checkmark, else it should be unchecked and hidden, can someone help please?

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
Sep 30, 2025 8:43 AM UTC

Yes, you can use this script (assuming your fields are named Dropdown1-5 and Check Box1-5) as custom calculation script in first dropdown field, when you add more fields just replace 5 with the number of the fields:

for(var i=1; i<=5; i++){
 var check = this.getField("Check Box"+i);
 var drop = this.getField("Dropdown"+i).valueAsString;

if (drop == "Yes" || drop == "No") {
 check.style = (drop == "Yes") ? style.ch : style.cr;
 check.textColor = (drop == "Yes") ? color.green : color.red;
 check.strokeColor = (drop == "Yes") ? color.green : color.red;
 check.checkThisBox(0, true);
 check.display = display.visible;}
else {
 check.display = display.hidden;
 check.checkThisBox(0, false);}}

5 replies

JR Boulay
Community Expert
Community Expert
Sep 25, 2025 8:25 AM UTC

[MOVED TO THE ACROBAT PRO DISCUSSIONS]

Translate
Acrobate du PDF, InDesigner et Photoshopographe
Nesa Nurani
Community Expert
Community Expert
Sep 22, 2025 5:40 AM UTC

Just to add, if user will only write Yes or No, it is better to use a dropdown field with those choices.

Translate
Nesa Nurani
Community Expert
Community Expert
Sep 22, 2025 4:57 AM UTC

You can use this as 'Validate' script of text field:

var f = this.getField("Check Box1");

if (event.value == "Yes" || event.value == "No") {
 f.style = (event.value == "Yes") ? style.ch : style.cr;
 f.textColor = (event.value == "Yes") ? color.green : color.red;
 f.strokeColor = (event.value == "Yes") ? color.green : color.red;
 f.checkThisBox(0, true);
 f.display = display.visible;}
else {
 f.display = display.hidden;
 f.checkThisBox(0, false);}
Translate
blazbAuthor
Inspiring
Sep 30, 2025 8:40 AM UTC

Thank you for that.
I have gone with the dropdown as you suggested, I have actually now add 5 dropdowns and corresponding checkboxes, can I use one script instead of putting script in each field, because down the line number of fields may get bigger?

Translate
Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
Sep 30, 2025 8:43 AM UTC

Yes, you can use this script (assuming your fields are named Dropdown1-5 and Check Box1-5) as custom calculation script in first dropdown field, when you add more fields just replace 5 with the number of the fields:

for(var i=1; i<=5; i++){
 var check = this.getField("Check Box"+i);
 var drop = this.getField("Dropdown"+i).valueAsString;

if (drop == "Yes" || drop == "No") {
 check.style = (drop == "Yes") ? style.ch : style.cr;
 check.textColor = (drop == "Yes") ? color.green : color.red;
 check.strokeColor = (drop == "Yes") ? color.green : color.red;
 check.checkThisBox(0, true);
 check.display = display.visible;}
else {
 check.display = display.hidden;
 check.checkThisBox(0, false);}}
Translate