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

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

Community Beginner ,
Oct 28, 2024 Oct 28, 2024

Copy link to clipboard

Copied

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.

kzual0max_1-1730145976181.png

 

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.

kzual0max_2-1730146005140.png

 

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.

TOPICS
General troubleshooting , JavaScript , PDF forms

Views

203

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , Oct 28, 2024 Oct 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.

Votes

Translate

Translate
Community Expert , Oct 29, 2024 Oct 29, 2024

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.

Votes

Translate

Translate
Community Expert ,
Oct 28, 2024 Oct 28, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

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.

kzual0max_1-1730207247877.png

 

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.

Votes

Translate

Translate

Report

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 ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

 

I have tried again, without any change in behavior from Adobe. 

 

"if you change the calculation script before you close the window it will disappear your script"

 

I am not closing any window (that I am aware of) until I paste the code in the Javascript editor, at which point I can only click on 1 of 3 things:

1. OK (closes the Javascript editor and I assume saves the code - I have not yet seen that per se)

2. Cancel (closes the Javascript editor, I assume without saving)

3. Go To... (opens a dialog box asking me a Line Number)

 

In order, what happens is this:

- I click the Custom calculation script radio button

- I click the Edit button to open the Javascript editor

- I paste the code in the Javascript Editor

- I click the OK button in the Javascript Editor - which automatically closes the Javascript Editor

- Immediate return to the Dropdown Properties interface

- The code shows up here for barely a fraction of a second, then disappears

kzual0max_0-1730223696724.png

- Immediate and automatic selection of the "Value is not calculated option" radio button

 

The only window I close manually is the Javascript editor, and I am not doing it before pasting the code in. I am not doing anything between pasting the code in and clicking OK to close the window. At this point I have no idea whether or not the script has been saved or not, but when I go back in the document and select the right option in the dropdown menu, nothing shows up. 

Votes

Translate

Translate

Report

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 ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

Your description to be correct.  I wonder if it's a setting under Edit > Preferences (Ctrl +k).

Votes

Translate

Translate

Report

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 Beginner ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

Yup, it works perfectly fine now! Thank you so much, this is exactly what I wanted!

Votes

Translate

Translate

Report

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 ,
Oct 29, 2024 Oct 29, 2024

Copy link to clipboard

Copied

LATEST

You're welcome.  I use Notepad as my Acrobat JavaScript editor because there's more features and the capacity of the built-in one is limited.  This article I wrote explains how to change it under the JavaScript section.

Votes

Translate

Translate

Report

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