Hide/show checkbox based on another checkbox

New Here ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

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. 

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms , Rich media and 3D

Views

136

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Nov 22, 2021 Nov 22, 2021

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

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

Likes

Translate

Translate
Adobe Community Professional ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Make sure the export value of the first field is indeed "Yes".

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

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

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Thanks for all your inputs. Nesa Nuranis suggestion does exactly what I wanted 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Looks like I broke my own rule that I teach my students: Don't test for "Yes",  check for not "Off". The reason for this is that you can redefine the "On" state, and it defaults to "Yes", the "Off" value cannot be redefined, it is always "Off". This means to create code that always works, forget that there is an "On" or "Yes" state, and only test for the opposite. This will always work. Why did I make this mistake? Because I never redefine the "On" state, so I can rely on it being "Yes". With that in mind, you can do the following (I understand that you already have a working system, but just in case you will dive deeper into JavaScript programming) for the custom validation script: 

 

if (event.target.value == "Off") {
    this.getField("CheckBox2").display = display.hidden;
}
else {
    this.getField("CheckBox2").display = display.visible;
}

As you can see, I am now testing for the "Off" state, and I flipped the two cases around. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

LATEST

Hi,

 

My question is a bit similar to this one, hence I have "piggy-backed" here. I have a listings where more than one selection can be made and  output copied to a text field. However, it only copies over one selection and leaves text field blank if more than one selection is made.

 

Can you kindly advise

 

Regards

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Give the export value "Yes" to checkbox 1

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines