These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Get the new export value?

miQlo
Registered: Jul 13 2010
Posts: 44
Answered

I have a list in a combobox, each item has an export value.
 
How do I make the export value for a combobox to change before the keystroke event, or how do I get the export value from the item that is being selected?
 
If I put the code below in the keystroke event for the combobox it prints the value that was before the selection from the combobox was made, I need the export value from the selected item.
 
console.println(this.getField("MyComboBox").value);

My Product Information:
Acrobat Pro 9.4, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Accepted Answer
You need to refer to the correct object and property to capture this data. The 'this.getField("MyComboBox").value' within the focused field until the field is committed refers to the value prior to the field receiving focus or entry. You might try using the 'event.changeEx'. The 'changeEx' contains the value of the changed export value. The 'event.value' contains the value prior to the key press.

To see how all of this happens, try the following code in the custom keystroke script:

console.println("field value: " + this.getField("MyComboBox").value);
console.println("event value: " + event.value);
console.println("event changeEx: " + event.changeEx);

You will also need to set the combo box to 'commit immediately' and use the up and down arrow keys to select the option.

More information about events and event properties is contained in the Acrobat JS API Reference.

George Kaiser

miQlo
Registered: Jul 13 2010
Posts: 44
Ok I get it. It runs the script twice though witch results in different values in each run, and in the last run the changeEx value is null so I added if (event.changeEx){ .... and it only runs once, is that the correct way?

this is what prints in the console before my addition:
field value: 1
event value: One
event changeEx: 2
field value: 1
event value: Two
event changeEx:

However my script works the way I want with changeEx now, thank you.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
It runs twice because it executes once when the item is selected and again when it is committed. To confirm, add the following line to what you have:

console.println("event willCommit: " + event.willCommit);

So your code should test for this property and execute the rest if it is false:

if (!event.willCommit) {

// rest of your code goes here.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
The purpose of the script was to show how the different value properties (getField().value, event.value, and event.chagneEx) change when there is a change the selection in the combo box or drop down box. If you uncheck the 'commit select item immediately' option, the way the values display will change. There could even be a change if you use 'this.getField(event.target.name).value.

George Kaiser