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.
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.
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.
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.
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.
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.
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.
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.
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
- 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.
Copy link to clipboard
Copied
Your description to be correct. I wonder if it's a setting under Edit > Preferences (Ctrl +k).
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.
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.
Copy link to clipboard
Copied
Yup, it works perfectly fine now! Thank you so much, this is exactly what I wanted!
Copy link to clipboard
Copied
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.