Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating hidden/visible fields based on one radio group selection

New Here ,
Mar 17, 2025 Mar 17, 2025

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

TOPICS
How to , JavaScript
163
Translate
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
Community Expert ,
Mar 17, 2025 Mar 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}

Translate
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 ,
Mar 17, 2025 Mar 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.

Translate
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
Community Expert ,
Mar 17, 2025 Mar 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.

 

Translate
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 ,
Mar 17, 2025 Mar 17, 2025

So main the issue i found was me not typing exactly the name of the field, so THANK YOU for that catch. Follow up question now. For the rest of the fields, i would just copy the same script and replace the names with the fields that will need to populate? or is the script you provided the best used one? I am using mouse up for the action btw.

Translate
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 ,
Mar 17, 2025 Mar 17, 2025

Also, I currently have the script in the "paper check" and "ACH" which is the radio group buttons themselves or should it be in the "selection" which is the parent name of the radio group?

Translate
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
Community Expert ,
Mar 17, 2025 Mar 17, 2025

Remove the scripts from every field except a text field that is not any of the fields in the script.

Translate
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 ,
Mar 17, 2025 Mar 17, 2025
LATEST

Awesome. Thank you so much!!

Translate
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