Skip to main content
New Participant
November 19, 2021
Answered

Hide/show checkbox based on another checkbox

  • November 19, 2021
  • 2 replies
  • 5578 views

Hi,

I am very new to Adobe, and currently creating a fillable form for intern work.

 

Is there a way to hide/show a checkbox based on whether or not another checkbox is checked/unchecked?

 

I want "box2" to show only if "box1" is checked. If "box1" is unchecked, "box2" should be hidden.

 

I've been looking around the forum and elsewhere, but can't really seem to find a solution. 

 

Additional info: "box1" is "pre-checked", so that when colleagues open the file, "box1" will already be checked (they're supposed to uncheck boxes themselves). So when they remove the check / uncheck "box1", "box2" will become hidden. 

This topic has been closed for replies.
Correct answer Nesa Nurani

You can use this code as Mouse UP event of CheckBox1:

this.getField("CheckBox2").display = event.target.value == "Off" ? display.hidden : display.visible;

2 replies

JR Boulay
Community Expert
November 22, 2021

Give the export value "Yes" to checkbox 1

Acrobate du PDF, InDesigner et Photoshopographe
Karl Heinz  Kremer
Community Expert
November 19, 2021

Let's say you have a checkbox named CheckBox1 and another one named CheckBox2, and you want to hide CheckBox2. The following script, when used as a "MouseUp" action for CheckBox1 will do this:

 

if (event.target.value == "Yes") {
    this.getField("CheckBox2").display = display.visible;
}
else {
    this.getField("CheckBox2").display = display.hidden;
}
enyl3Author
New Participant
November 22, 2021

Hi Karl,

 

Thank you. This seems to "almost" do the job. When I uncheck "CheckBox1", "CheckBox2" becomes hidden (which is exactly what I wanted). But when I check "CheckBox1" again, "CheckBox2" remains hidden. Is there a way to make it so that "visibility" of "CheckBox2" constantly depends on whether or not "CheckBox1" is checked?

Participating Frequently
August 31, 2022

You can use this code as Mouse UP event of CheckBox1:

this.getField("CheckBox2").display = event.target.value == "Off" ? display.hidden : display.visible;


Hi Nesa,

 

Thank you for the above. This worked for half of my form, wondering if you might be able to help figure out why the same will not work on the other half.

 

So i have two checkboxes 'checkbox1' and 'checkbox2'. 'checkbox1' is related to 'checkboxA', 'checkboxB', 'checkboxC' and 'checkbox2' is related to 'checkboxD', 'checkboxE', 'checkboxF'.

 

Your code above worked for 'checkbox1' : 'checkboxA', 'checkboxB', 'checkboxC' but will not work for 'checkbox2' : 'checkboxD', 'checkboxE', 'checkboxF'

 

I am very new to this and self-learning as I go. Appreciate your guidance.