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

How do I show the selected item name (and not the value) of a dropdown box in another text box

Community Beginner ,
Oct 14, 2020 Oct 14, 2020

I'm pretty new to scripting for PDF forms, please could you help me?

I have a dropdown box with 2 items in it 'ITEM A & ITEM B' with values $20 for ITEM A and $30 for ITEM B. I wish to copy the selected ITEM (and not the VALUE) to a new textbox. Is there an easy way to do this, I have seen a couple of scripts online but none seem to work for me or maybe I'm just doing it wrong. If you are kind enough to be able to help could you please refer to where the script should sit in either the Dropdown box or the textbox. Thank you so much.

TOPICS
How to , PDF forms
2.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 14, 2020 Oct 14, 2020

I prefer to run the script from the texfield using a custom calculation script. See the method below:

 

 

var f = this.getField("myDropdown");
var a = f.currentValueIndices;
event.value =  f.getItemAt(a, false);

 

 

currentValues.png

 

The field method above employ the use of "currentValueIndices" to get the index of the listed items in your dropdown menu which is declared in variable "a" in the script above. Then you use "getItemAt" to get the face value of that indexed item.

 

According to the Acrobat API reference you cannot get the face value of a combobox using the regular method unless both the face value and the export value are the same. In other words, if you only need to get the export value then just use :

 

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

 

as the custom calculation script in your 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 ,
Oct 14, 2020 Oct 14, 2020

I prefer to run the script from the texfield using a custom calculation script. See the method below:

 

 

var f = this.getField("myDropdown");
var a = f.currentValueIndices;
event.value =  f.getItemAt(a, false);

 

 

currentValues.png

 

The field method above employ the use of "currentValueIndices" to get the index of the listed items in your dropdown menu which is declared in variable "a" in the script above. Then you use "getItemAt" to get the face value of that indexed item.

 

According to the Acrobat API reference you cannot get the face value of a combobox using the regular method unless both the face value and the export value are the same. In other words, if you only need to get the export value then just use :

 

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

 

as the custom calculation script in your 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 ,
Oct 15, 2020 Oct 15, 2020
LATEST

Thank you so much, super quick and worked like a dream. Perfect answer and so informative I feel I've actually learnt something rather than just copying and pasting a snippet. It's a shame this is not a standard in the calculation options (show item selected with a reference) I know you should use the value as the selected item but if that is being used for another calculation then the item is nnext best thing). Thank you again you are a credit to the community.

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