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 14, 2025

Are you copying, pasting, and selecting the entire code before running it?  That error would suggest you ran the last line only.

 

https://pdfautomationstation.substack.com/p/the-javascript-console


sorry for the delay - had to get the form done (as best as I could) and submitted. Would still really like to get this figured out as I knw there will be revisions. 

 

so the short answer is yes, I did highlight everything and hit enter from my keypad (like your video instructs) but am still getting a null error 

 

interestingly, if I add PDF Automation's line (this.exportDataObject({cName:"FieldNameList.txt", nLaunch:2});) it works and generates a text file - attached.

 

Possible syntax error in the (this.createDataObject("FieldNameList.txt", strReport);) function?