Skip to main content
New Participant
October 28, 2024
Answered

How to show a text field when selecting option from dropdown menu?

  • October 28, 2024
  • 1 reply
  • 2096 views

I want to modify a form so that when one specific option from a dropdown menu is selected, it displays a text field underneath. So far I've only found that this is possible through Javascript. I know nothing about Javascript but here's what I found: 

 

if (this.getField("DropdownMenuName").value == "TextOfTheSpecificOption")

{ this.getField("TextFieldName").display = display.visible; }

else { this.getField("TextFieldName").display = display.hidden; }

 

My dropdown menu's name is "Dropdown2"

The text of the specific option is "Transfer to another restaurant"

My text field's name is "TransferTo"

 

This is the actual code I've saved.

 

But it does not seem to work. Upon selecting the option, nothing happens. No text field showing up, no error message, no nothing.

 

I've set the TransferTo text field properties as such.

 

What am I missing? Also, if any of you know a simpler way to do this, please let me know, because Javascript is basically alien language to me. Thanks to anyone who can help.

Correct answer PDF Automation Station

I think I found why the code disappears from the display box. It doesn't like the source I copied the code from. When I paste the text in Notepad, then copy it again and paste it again in the Javascript editor, now it keeps the code visible. And now I do see the text field show up! But there's a new problem: it does not show up when selecting the option itself, but rather after that, when clicking a second time, away from the dropdown menu.


Under Edit >Prefences>Security (enhanced), if "Enable protected mode at startup" is checked, it will prevent pasting from certain sources.  Notepad is plain text so pasting there first, and copying from there is the workaround.  In the options tab of the dropdown field, select "Commit selected value immediately" and script should hide and show the field without having to tab out of the dropdown.

1 reply

PDF Automation Station
Community Expert
October 28, 2024

The script should not be in a Mouse Up action of the text field.  Remove it from there an paste into a custom calculation script of another text field.

kzual0maxAuthor
New Participant
October 29, 2024

Thanks for the suggestion. I have assumed that by pasting the code into the custom calculation script of another text field, you meant to delete the one I had created and to create a new one, which is what I did. I then pasted the code into the new text field's custom calculation script, but as soon as I hit OK in the Javascript editor, the "Custom calculation script" radio button got deselected automatically, the code went away as if I didn't put anything and the option "Value is not calculated" got automatically selected again, no idea why.

 

After that, the new text field did not show up after selecting the right option in the dropdown menu. I don't think I've done anything contrary to the instructions you provided. I'll keep looking for a solution.

PDF Automation Station
Community Expert
October 29, 2024

You have followed my instructions.  Sometimes, if you change the calculation script before you close the window it will disappear your script.  Please try again.