Show/Hide Field and Check a Box Questions with a Twist

Explorer ,
Jun 24, 2019

Copy link to clipboard

Copied

1.  I need to show/hide a text field based on 4 Yes/No drop dropdowns.

-There are 4 dropdowns with only the options Yes and No.

-There is a message that must become visible if ANY selection is No.

The main problem I am running into is if 2 or more are changed to no and then you change 1 to yes, it removes the message although there is still at least 1 that says no.  I have attempted to do an export value and have a hidden calculation text field with an "if >0", "make visible" but I was guessing with the code so it didn't work.

2.  I need to check 1 checkbox based on 4 other checkboxes.

-There are 4 checkboxes and 1 hidden checkbox.

-I need the hidden checkbox to be checked of 1 or more of the other checkboxes are checked.

This may seem like a strange request but it stems from the need to spawn a page.  I have figured out how to spawn/delete an info page based on 1 checkbox but this causes problems with multiple checkboxes. I can't stop it from spawning multiple pages based on multiple checkmarks.  I only ever need 1 info page to be spawned.  i figured if I can check a hidden box that it would fix the problem but you Pro's may have the right solution. 

I have little to no Java experience. What I have learned so far has been from these forums over the past few weeks so a little extra detail on a solution would be really appreciated.  If I need to provide a document sample I can.  I also an trying to do these without lifecycle which, based on what I have see so far, should be possible.

Thanks in advance.

JT

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use the following code as the custom calculation script of a (hidden) text field to achieve both things (adjust the field names as necessary):

var v1 = this.getField("Dropdown1").valueAsString;

var v2 = this.getField("Dropdown2").valueAsString;

var v3 = this.getField("Dropdown3").valueAsString;

var v4 = this.getField("Dropdown4").valueAsString;

this.getField("FIELD NAME").display = (v1=="No" || v2=="No" || v3=="No" || v4=="No") ? display.visible : display.hidden;

var v1 = this.getField("Checkbox1").valueAsString;

var v2 = this.getField("Checkbox2").valueAsString;

var v3 = this.getField("Checkbox3").valueAsString;

var v4 = this.getField("Checkbox4").valueAsString;

this.getField("Checkbox5").checkThisBox(0, (v1!="Off" || v2!="Off" || v3!="Off" || v4!="Off"));

TOPICS
Acrobat SDK and JavaScript, Windows

Views

217

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

Show/Hide Field and Check a Box Questions with a Twist

Explorer ,
Jun 24, 2019

Copy link to clipboard

Copied

1.  I need to show/hide a text field based on 4 Yes/No drop dropdowns.

-There are 4 dropdowns with only the options Yes and No.

-There is a message that must become visible if ANY selection is No.

The main problem I am running into is if 2 or more are changed to no and then you change 1 to yes, it removes the message although there is still at least 1 that says no.  I have attempted to do an export value and have a hidden calculation text field with an "if >0", "make visible" but I was guessing with the code so it didn't work.

2.  I need to check 1 checkbox based on 4 other checkboxes.

-There are 4 checkboxes and 1 hidden checkbox.

-I need the hidden checkbox to be checked of 1 or more of the other checkboxes are checked.

This may seem like a strange request but it stems from the need to spawn a page.  I have figured out how to spawn/delete an info page based on 1 checkbox but this causes problems with multiple checkboxes. I can't stop it from spawning multiple pages based on multiple checkmarks.  I only ever need 1 info page to be spawned.  i figured if I can check a hidden box that it would fix the problem but you Pro's may have the right solution. 

I have little to no Java experience. What I have learned so far has been from these forums over the past few weeks so a little extra detail on a solution would be really appreciated.  If I need to provide a document sample I can.  I also an trying to do these without lifecycle which, based on what I have see so far, should be possible.

Thanks in advance.

JT

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use the following code as the custom calculation script of a (hidden) text field to achieve both things (adjust the field names as necessary):

var v1 = this.getField("Dropdown1").valueAsString;

var v2 = this.getField("Dropdown2").valueAsString;

var v3 = this.getField("Dropdown3").valueAsString;

var v4 = this.getField("Dropdown4").valueAsString;

this.getField("FIELD NAME").display = (v1=="No" || v2=="No" || v3=="No" || v4=="No") ? display.visible : display.hidden;

var v1 = this.getField("Checkbox1").valueAsString;

var v2 = this.getField("Checkbox2").valueAsString;

var v3 = this.getField("Checkbox3").valueAsString;

var v4 = this.getField("Checkbox4").valueAsString;

this.getField("Checkbox5").checkThisBox(0, (v1!="Off" || v2!="Off" || v3!="Off" || v4!="Off"));

TOPICS
Acrobat SDK and JavaScript, Windows

Views

218

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
Jun 24, 2019 1
Most Valuable Participant ,
Jun 24, 2019

Copy link to clipboard

Copied

What are the names of the fields involved in both of these tasks?


Also, it's JavaScript, not Java...

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
Reply
Loading...
Jun 24, 2019 0
Explorer ,
Jun 24, 2019

Copy link to clipboard

Copied

See the image attached.  If the box is checked then the TDY LOCATION1 should be hidden and LEAVE LOCATION1 be visible.

if 2nd box is checked then TDY LOCATION2 should be hidden and so on and so on.

tdyleave.PNG

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
Reply
Loading...
Jun 24, 2019 0
Most Valuable Participant ,
Jun 24, 2019

Copy link to clipboard

Copied

And the names of the drop-down fields for issue #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
Reply
Loading...
Jun 24, 2019 0
Explorer ,
Jun 25, 2019

Copy link to clipboard

Copied

Its just Dropdown1, Dropdown2....4

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
Reply
Loading...
Jun 25, 2019 0
Most Valuable Participant ,
Jun 25, 2019

Copy link to clipboard

Copied

You can use the following code as the custom calculation script of a (hidden) text field to achieve both things (adjust the field names as necessary):

var v1 = this.getField("Dropdown1").valueAsString;

var v2 = this.getField("Dropdown2").valueAsString;

var v3 = this.getField("Dropdown3").valueAsString;

var v4 = this.getField("Dropdown4").valueAsString;

this.getField("FIELD NAME").display = (v1=="No" || v2=="No" || v3=="No" || v4=="No") ? display.visible : display.hidden;

var v1 = this.getField("Checkbox1").valueAsString;

var v2 = this.getField("Checkbox2").valueAsString;

var v3 = this.getField("Checkbox3").valueAsString;

var v4 = this.getField("Checkbox4").valueAsString;

this.getField("Checkbox5").checkThisBox(0, (v1!="Off" || v2!="Off" || v3!="Off" || v4!="Off"));

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
Reply
Loading...
Jun 25, 2019 0