Skip to main content
Known Participant
November 11, 2025
Question

JS to hide or show a group of fields

  • November 11, 2025
  • 1 reply
  • 149 views

(semi)newbie to javascript - go (somewhat) easy on me :O)

 

short version... working on a form where I need to either show a bunch of fields or hide them base on radio button choice.

 

Right now I have the fields visible (or hidden) based on the button's Action/Show/Hide Field. It works but there are +/-75 fields and it's cumbersome, at best.

 

Logically, I would like to group those +/-75 feilds but have no idea if this is available!?

 

Any help would be appreciated.   

1 reply

PDF Automation Station
Community Expert
Community Expert
November 11, 2025

Name the fields in the group with a hierarchical numbering scheme creating the first field, then right-click>Create multiple copies with 1 across and the rest down.  You will end up with fields named, for example, Text1.0 through Text1.74.  You can then create a calculation that loops through the fields and sets the visibility (display property).  Alternatively, you can put a custom calculation in the first field before using right-click > Create multiple copies that will show or hide depending on the value of the radio button choice:

if(this.getField("Radio 1").value == "A")

{event.target.display=display.hidden}

else

{event.target.display=display.visible}

 

If your fields don't have a numbering scheme and you don't want to individually enter a calculation script into every single field, this trick is for you:

https://pdfautomationstation.substack.com/p/secret-trick-for-changing-properties

HambergAuthor
Known Participant
November 11, 2025

Great info (for the next one :O/)!

Any easier way (short of renaming) if I have the 75+ fields (consisting of radio buttons, check boxes and text boxes) already named?

HambergAuthor
Known Participant
November 11, 2025

Here's a specific explanation on how to show/hide fields:

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm

 

And yes there is a way to generate and export a list of fields and their properties, but it's not a feature of Acrobat. You need a script for it. 

 

See the first tool on this list of free tools:  "Find Required Fields"

https://www.pdfscripting.com/public/Free_Acrobat_Automation_Tools.cfm

 

Here's an example of some code you could run from the console window. 

 

var strReport = "";
for(var i=0;i<this.numFields;i++)
{
     strReport += this.getNthFieldName(i) + "\n";
}
this.createDataObject("FieldNameList.txt", strReport);

 

This short script collects all field names into a variable named strReport, and then uses it to create a text file attachment to the current PDF. 

 


console is generating an error msg:

var strReport = " ";
for(var i=0;i<this.numFields;i++)
{
strReport += this.getNthFieldName(i) + "\n";
}
this.createDataObject("FieldNameList.txt", strReport);

ReferenceError: strReport is not defined
1:Console:Exec
undefined