Skip to main content
Participating Frequently
March 17, 2025
Question

Creating hidden/visible fields based on one radio group selection

  • March 17, 2025
  • 1 reply
  • 391 views

Hello,

 

We have a document that works already but needs to add some verabage and i cannot edit the exiting document and i am having to recreate it. The current form works this way but I am trying to do a very simple Radio Buttion option and depending on what option they choose, some fields will appear and others will stay hidden. I am attempting to you this code:

 

{
// Get the selected value from the radio button group
var selectedValue = this.getField("Selection").value;

// Get the field that will be shown/hidden
var textField = this.getField("Payee Name");

// Show or hide the field based on the selected radio button value
if (selectedValue == "Paper Check") {
textField.display = display.visible; // Show the field
} else if (selectedValue == "ACH") {
textField.display = display.hidden; // Hide the field
} else {
// Optionally, hide the field if no selection is made
textField.display = display.hidden;
}

}

 

But this is not working. I would like to be able to include all fields that would either disappear or be visible into one script to keep things neat. Thanks in advance

1 reply

PDF Automation Station
Community Expert
Community Expert
March 17, 2025

That should work as long as the radio button export values are exactly as written.  Also, where is this script.  If it is in the "Payee Name" field, this.getField("Payee Name") should be change to event.target first and last curly braces should be removed.  If "Paper Check" is the only value where the field will be visible you don't need the else if statement.  Just use this:

if(this.getField("Selection").value=="Paper Check")

{event.target.display=display.visible}

else

{event.target.display=display.hidden}

josh_2389Author
Participating Frequently
March 17, 2025

Hello,

One of the fields i want to is "payee name" when "paper check" is selected. The other field "merchant name" is to be shown when "ACH" is selected and the "payee name" would be hidden again. I have this script placed radio button group labled "selection." When i run this neither field shows or hides.

PDF Automation Station
Community Expert
Community Expert
March 17, 2025

You would have to use a mouse up action in all radio buttons.  Instead use the following custom calculation script an another text field, not the 2 mentioned:

 

var pn=this.getField("payee name");
var mn=this.getField("merchant name");
pn.display=display.hidden;
mn.display=display.hidden;
if(this.getField("selection").value=="paper check")
{pn.display=display.visbile}
if(this.getField("selection").value=="ACH")
{mn.display=display.visible}

 

Note that all export values and field names are case sensitive.  Make sure they match exactly.