Skip to main content
Participant
June 30, 2020
Question

How do I create an image from a drop down menu and autofill a seperate text with said menu?

  • June 30, 2020
  • 2 replies
  • 5848 views

I am >very< new to scripting, I want to have an an image pop up when we select something from one dropdown list and on another I'd like to have specific texts boxes other dropdown menus fill themselves when a specific item is picked, ex: selecting swordman class autoputs sword in equipment field.

2 replies

ls_rbls
Community Expert
Community Expert
July 4, 2020

I need to ask if this is for D&D game?

 

Below is a very very simple script example to illustrate one of the many possible ways it could be implemented with Javascript&colon;

 

 

 

if (event.value =="sword") {this.getField("EQUIPMENT").value = "sword"; this.getField("IMAGE").display = display.visible}

else if ( event.value =="gauntlets of Ogre power") {this.getField("EQUIPMENT").value = "gauntlets of Ogre power"; this.getField("IMAGE").display = display.hidden }

else this.getField("EQUIPMENT").value = "";

 

 

 

 

 

And this is how the script above looks like when executed through the dropdown menu as a custom calculation script:

 

Image1:

 

 

 

Image 2:

As mentioned by Try67, the only problem is that in order to cycle through images in that same location in that page, AND,  as the user selects a different item from the dropdown menu, it definitely involves advanced javascripting which is totally different from my example above.

 

However, in my example below I set two image fields to the same size,  both fields are also set to read only ( and right on top of each in the same location on that page), and also set as hidden.

 

Below is a little more elaborated script that  I'm using just to illustrate an example of how you can still achieve a similar result without too much advanced scripting knowledge  nor PDF design knowledge:

 

 

 

 

 

if (!event.willCommit) {
{
this.getField("EQUIPMENT").value = event.target.value;
}

if (event.value =="sword") {this.getField("SWORD").display = display.visible} else { this.getField("SWORD").display = display.hidden;}

if ( event.value =="gauntlets of Ogre power") {this.getField("GAUNTLET").display = display.visible } else {this.getField("GAUNTLET").display = display.hidden;}

}

 

 

 

 

 

 

You can continue to do this for all the items you want (or have in that dropdown menu). 

 

And see slides below to appreciate how this non-elegant and  non-professionally made javascript behaves when executed  🙂 

 

 

 

 

 

 

 

 

 

 

 

 

Participating Frequently
May 3, 2023

This is the exact type of project I am working on. For the purpose of eliminating any possible problems I copied the code and names of fields but I’m not having an luck in it working.

 

I imported the script into Document Javascripts.

 

Suggestions?

ls_rbls
Community Expert
Community Expert
May 4, 2023

Hi @Greg28740296rxp2 ,

 

Happy to see an Acrobat user updating this thread.

 

Are both the field names in the script and the dropdown field object names spelled exactly the same?

 

Also, can you clarify in more detail what exactly is not working for you?

 

Are you getting any errors?

try67
Community Expert
Community Expert
June 30, 2020

There's no such thing as an image pop-up in PDF files. You can create something like it, but it requires some advanced scripting know-how. However, it's certainly possible to make an image appear (or disappear) once a selection has been made in a normal (textual) drop-down field, as well as populating the value of another field with some text.

For the latter you can use something like this as the custom validation script of the drop-down field:

if (event.value=="sword") this.getField("equipment").value = "sword";

Note that JavaScript is case-sensitive, so this won't work if your value is actually "Sword" or the field name is actually "Equipment". You'll need to make sure they match perfectly for it to work.