Skip to main content
Inspiring
September 22, 2025
Answered

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

  • September 22, 2025
  • 3 replies
  • 243 views

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?

Correct answer Nesa Nurani

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);}}

3 replies

JR Boulay
Community Expert
Community Expert
September 25, 2025

[MOVED TO THE ACROBAT PRO DISCUSSIONS]

Acrobate du PDF, InDesigner et Photoshopographe
Nesa Nurani
Community Expert
Community Expert
September 22, 2025

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

Nesa Nurani
Community Expert
Community Expert
September 22, 2025

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);}
blazbAuthor
Inspiring
September 30, 2025

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?

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 30, 2025

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);}}