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

Form JavaScript to add text value after drop-down selection

New Here ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi, I'm new to this and need help with a form in Adobe Acrobat Pro DC. 

I created a nomination form where a user can choose an award from a drop-down list named "Type of Award". When a user selects an award, I would like text to populate in text field "Criteria". 
I tried JavaScript examples from other threads and YouTube with no luck. 
Any help would be greatly appreciated. 


TOPICS
Create PDFs , JavaScript , PDF forms

Views

3.6K

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 ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

- What text? The same one as selected in the drop-down, or something else?

- Should this text be editable by the user, or should it only be determined by the selection in the drop-down?

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
New Here ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Thanks for the fast reply.
 

New text that can be edited by the user.


The drop down list "Type of Awards" will have a few options (Service Award, Achievment medal, etc). When a user selects an option, I am hoping text will populate in a text field showing the user what's required for the selected award that can be editable. 


If user selects 'Service Award' then text will populate "Describe achievement in 300 characters or less. I'd like to recognize my employee because..."

 

The user can choose to overwrite completely or add to it. 

Also, if possible, can you help guide me where this code should be added. In Acrobat Pro, I placed the code in the drop-down list properties Action tab as a  mouse exit event. Reading other threads mention to place in a validation box that's now confusing. 

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 ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

As the custom validation script of the drop-down field enter this:

 

if (event.value=="Service Award") this.getField("Criteria").value = "Describe achievement in 300 characters or less. I'd like to recognize my employee because...";

 

Duplicate the line for each value.

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
New Here ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

Yeah! Worked on first try. thank you thank you

 

Saving this code in a safe place.

 

Will this work on radio buttons too?

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 ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

Radio buttons don't have a validation event, but you can use the Mouse Up event, instead.

However, the value should be accessed then using event.target.value instead of just event.value.

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
New Here ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

Hi try67,  I'm having the same problem.  I have followed your instruction above but it's not working.  I copied and pasted the code exactly into the custom validation script of the drop-down field like this:

if (event.value=="1 - Defensive") this.getField("Notes").value = "Defensive investors tend to target capital preservation...";
if (event.value=="2 - Very cautious") this.getField("Notes").value = "Very cautious investors tend to target a return above deposit rates....";

 

I can's see what I am doing wrong, under Options I have the Commit selected value immediately ticked.

Thanks

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 ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

Script should work fine. Make sure choices are exactly the same in dropdown as they are in script.

You can share the actual file with us if you can't make it work.

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
New Here ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

Hi Nesa, thanks for the quick response - I double-checked all that and now have found a workaround by setting the export value of each item as the text I want to be displayed in my Textbox and running a script in the textbox instead: event.value=this.getField("Risk").value;
 (but it's bugging me why the origianl method doesn't work!).

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 ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

LATEST

A single character being off (such as an extra or a missing space, or a letter that's lower-case instead of upper-case) will cause the comparison to fail.

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