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

Populating Text Field Based on Dropdown Item

Community Beginner ,
May 07, 2025 May 07, 2025

I am having trouble with the switch line in a script I am trying to create.  I am trying to get a text field to autofill with specific account number when the account type is selected from the dropdown button. I have tried using dropdownValue and eventValue as well putting a dot in between and still have the same syntax error each time.

kristin_5215_0-1746650964804.pngexpand image

 

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms
272
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
2 ACCEPTED SOLUTIONS
Community Expert ,
May 07, 2025 May 07, 2025

You must only use straight quotes in your code, not curly ones.

View solution in original post

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 ,
May 07, 2025 May 07, 2025

An alternative approach is to assign the desired codes as the export values for each dropdown choice. For example, for "Admissions," set the export value to T22000-P170-82000-41, and apply similar formatting for the remaining options.

Then, in the custom calculation script of the text field, use the following code:

event.value = this.getField("Dropdown2").value;

This will ensure the selected export value is automatically populated in the text field.

View solution in original post

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 ,
May 07, 2025 May 07, 2025

You must only use straight quotes in your code, not curly ones.

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 Beginner ,
May 08, 2025 May 08, 2025

Do you mean quotation marks or parentheses? If quotation marks, not sure how mine sarted going from straight to angled.  I will retype them all and see if that helps.

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 ,
May 08, 2025 May 08, 2025

Quotation marks. It probably happened if you use an application like Word for writing the code, as it tends to do that automatically (unless you tell it not to). It's better to use a plain-text editor for your code. If you're on Windows, I highly recommend the free (and open-source) Notepad++.

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 Beginner ,
May 08, 2025 May 08, 2025

That did fix the syntax error.  I started typing the script in the form but then copied it to Word so I could see more of what I was typing & copy/pasting.  Still trying to get the script to run in the text box.  Trying Nesa's  approach now.  I am basically learning this as I go. No one in our IT department could help me with this.

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 ,
May 07, 2025 May 07, 2025

Start by quitting and restarting Acrobat, it often becomes unstable after trying several different JavaScripts.

Edit: try67 answer is full of common sense.


Acrobate du PDF, InDesigner et Photoshoptographe
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 ,
May 07, 2025 May 07, 2025

An alternative approach is to assign the desired codes as the export values for each dropdown choice. For example, for "Admissions," set the export value to T22000-P170-82000-41, and apply similar formatting for the remaining options.

Then, in the custom calculation script of the text field, use the following code:

event.value = this.getField("Dropdown2").value;

This will ensure the selected export value is automatically populated in the text field.

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 Beginner ,
May 08, 2025 May 08, 2025
LATEST

This worked!  Thank you so much Nesa and try67 for all your help!  I greatly appreciate it!

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