Toggle visibility of a group of fields with a button on a pdf form

New Here ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

Hi there, I'm a newbie and have what should be a simple task but I guess I am not familiar enough with the Java script syntax to make it work (not for lack of trying!).

 

I have the script working to make my group of fields visible or hidden, but do not know how to say

 

If it is (visible then

make it hidden

else

make it visible

 

It's a bit embarrasing as I know it is very simple but I am a VBA guy and Java script is still a mystery to me in terms of exact syntax without which it wont work!

 

Help appreciated.

 

Kind regards, Mark

TOPICS
PDF forms

Views

51

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 ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

It all depends where are you using code, for this tutorial lets say you want to make button to make field named "Text1" visible/hidden when you click on it.

In a button 'action' tab add this code as Mouse UP event -> Run  a JavaScript

if(this.getField("Text1").display == display.visible)
this.getField("Text1").display = display.hidden;
else this.getField("Text1").display = 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 ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

Hey Nesa,

 

Thank you very  much for that, it works beautifully:)

 

Just had to make it refer to the one field ("Hints.1") to reference the visible property, then applied tit to to the whole group ("Hints".

 

Seems Java Script is a lot less formal than VBA , for e.g. you don't need to finish off the If then else with an end if.

 

Thanks once again.

 

Kind regards, Mark

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
Most Valuable Participant ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

It's not less formal, but it is more flexible. If you don't include curly brackets after an if-statement then only the first command after it will be associated with it. Otherwise you have to place all the commands in a code block to associate them with the if-command, like this:

 

if (condition)

command1;

command2;

 

Only command1 is associated with the if statement.

 

if (condition) {

command1;

command2;

}

 

Both commands are associated with the if statement.

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 ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

LATEST

Thanks fo rthat, I was wondering the purpose of all thoise curly brackets!

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