Form JavaScript to add text value after drop-down selection
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.
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?
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.
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.
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?
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.
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
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.
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!).
Copy link to clipboard
Copied
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.

