Skip to main content
Known Participant
January 21, 2016
Answered

Display Export Value of dropdown instead of Item

  • January 21, 2016
  • 1 reply
  • 8165 views

I'm trying to show the Export Value of a dropdown instead of the selected option i.e. the user selects BLACK but the export value of BLK is actually displayed.  I can find lots of discussions on how to pull the export value and display it or use it to trigger another response in another field and I can usually tweak my existing JavaScripts when I need something new but I cannot seem to wrap my head around this!

This is my latest (failed) attempt

var f = this.getField("eyes");

if (event.value == "Black - BLK")

f.value = "BLK"

I'm using Acrobat PRO DC.

Any help is appreciated,

Thanks

Meabh


This topic has been closed for replies.
Correct answer George_Johnson

I've been doing this a long time, and have never heard of anyone wanting something like this, so it's interesting. Remove your current script and try the following as the custom Format script of the eyes dropdown:

// Custom Format script for dropdown

event.value = event.target.getItemAt(event.target.currentValueIndices, true);

This sets what's displayed in the dropdown to the export value of the selected item. Select the "Commit selected value immediately" option for the dropdown for the smoothest operation.

1 reply

Inspiring
January 21, 2016

Where did you place that script? What field and what event?

NHJB MHPAuthor
Known Participant
January 21, 2016

In the Custom Calculation Script of the "eyes" dropdown field.  I'm trying to get the Export Value to display in the dropdown field, not in a separate field. I can only assume I'm making this harder than it needs to be.

Meabh

Thom Parker
Community Expert
Community Expert
May 12, 2019

Why wouldn't it be saved in the PDF?  What good would any code be if it weren't?
A person on Reddit gave me this suggested code;

"event.value = event.value.substring(0,2);"

which effectively formats the output to truncate everything after the first two characters.  That code does save into the document.  I am able to send it to myself and it operates exactly as expected when I open the document in Acrobat Reader.
However, this suggestion comes with some issues as there are some codes that are going to be more than 2 digits long.


I'm not saying that the code isn't being saved, just that if it isn't working, that its a possibility. I think my other suggestion is more on the mark. And especially given that the second bit of code you posted does work.

The "substring" function is core JavaScript, whereas "event.target.currentValueIndices" is Acrobat specific. This would indicate that the code is saved and "Reader" implements the necessary core JS functionality, but not the Acrobat specific functionality.  Which suggest you are trying to view this PDF in the Mobile Reader. Is this true?

But of course this thread is about displaying the export value of the dropdown item. How is does this relate to using the substring function? You've left out a lot of information.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often