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

Make the exported value from a combobox trigger a function.

miQlo
Registered: Jul 13 2010
Posts: 44
Answered

I'm new to scripting and don't know the lingo yet so my explanation of my problem might be difficult to understand, sorry for that.

This script is based on Thom Parkers "Programming List and Combo fields in Acrobat and LiveCycle forms - Part 1"

Example 1 works great but I want to use an export value from the combobox instead as shown in Example 2 but that doesn't work. How do I make the export value to trigger the function?
My guess is that I have to change SetValues(event.value) but I don't know to what.

EXAMPLE 1
/*********** ComboBox1 keystroke *************/
if ( event.willCommit ) {
SetValues(event.value);
}
/**************************************************/

// Items in ComboBox1: "Talk to me"

/*********** Document-Level: SetValues *******/
var SpeakData = { "Talk to me": { speak1: "Hello world",
speak2: "and hello universe" }};
function SetValues(speakName)
{
this.getField("TextField1").value = SpeakData[speakName].speak1;
this.getField("TextField2").value = SpeakData[speakName].speak2;
}
/**************************************************/

EXAMPLE 2
/*********** ComboBox2 keystroke ************/
if ( event.willCommit ) {
SetValues(event.value);
}
/**************************************************/

// Items in ComboBox2: "Scream to me"
// "Scream to me" export value = 555

/*********** Document-Level: SetValues *******/
var ScreamData = { "555": { scream1: "Hello world",
scream2: "and hello universe" }};
function SetValues(speakName)
{
this.getField("TextField1").value = ScreamData[screamName].scream1;
this.getField("TextField2").value = ScreamData[screamName].scream2;
}
/**************************************************/

My Product Information:
Acrobat Pro Extended 9.3.1, Windows
miQlo
Registered: Jul 13 2010
Posts: 44
Ok i'll simplify it.

I have a combobox with one Item (MyItem). MyItem has an export value (MyExValue).
I have this script in the keystroke event.

if(event.willCommit) {
if(event.value == "MyItem") {
console.println("Item");
}
if(event.value == "MyExValue") {
console.println("Export Value")
}}

How do I make "Export Value" to show up in the console?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
So what's the problem, exactly? What is printed (if at all) to the console?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

miQlo
Registered: Jul 13 2010
Posts: 44
The only thing that is printed is "Item", that means that it takes the Item value from the combobox, but I want it to print the export value too.

When I select "MyItem" from the combobox I want it to print the export value for "MyItem".
If I execute this.getField("ComboBox").value it returns "Export Value", but when I use if(event.value == "MyExValue") it doesn't work because the event.value is "MyItem".

Sorry for my bad explanation my English isn't the best, hope you get it thou.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Try using event.target.value instead of event.value

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

miQlo
Registered: Jul 13 2010
Posts: 44
Yes that was what I was looking for, thanks allot. =)
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The problem was that the value of the event itself is the value you actually select, not the export value assigned to it. By looking at event.target.value you're actually looking at the value of the field (the "target" of the event), which is the export value.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

miQlo
Registered: Jul 13 2010
Posts: 44
Now I ran into another problem. event.target.value is not the current value but the previous. If I put the script on a button ill have to push the button twice to get the preferred value. Why is that?

It acts like rawValue in LiveCycle.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Hmmm... Probably because the event did not commit yet...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

miQlo
Registered: Jul 13 2010
Posts: 44
This is problem for me, there's got to be a workaround? I'll have to select the item twice from the combobox for it to work.

Maybe ill start a new post.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
No need to open another thread. Could you try using the validate event instead?
Try both event.value and event.target.value.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

miQlo
Registered: Jul 13 2010
Posts: 44
No that didn't work, it's still one choice behind.
miQlo
Registered: Jul 13 2010
Posts: 44
I can't solve this. I've uploaded a simplified version of my form that only contains my problem. I'd appreciate if you take a look at it.

http://www.speedyshare.com/files/23571509/ExportValue.pdf

(edit: small layout correction in the PDF)
try67
Expert
Registered: Oct 30 2008
Posts: 2398
There's probably a better way to do it, but this works...
Remove the script from the combo-box.
Use this as the text box's custom calculation script:
if (this.getField("MyComboBox").value!="none")event.value=this.getField("MyComboBox").getItemAt(this.getField("MyComboBox").value,false);else event.value = "";

If you will set the first item's export value to be 0, then you can just use:
event.value=this.getField("MyComboBox").getItemAt(this.getField("MyComboBox").value,false);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

miQlo
Registered: Jul 13 2010
Posts: 44
Just noticed that my uploaded example showed the same script in the text boxes, my bad. So you might have missed the document level script?

I need to populate more fields than one for every selection in my combo box, therefore I've put a list with alternatives at document-level.

And it goes a little bit something like this. (The script in the uploaded PDF is a bit shorter)
var MyData = {"1": {english: "One",italian: "Uno",german: "Ein"},"2": {english: "Two",italian: "Due",german: "Zwei"},"3": {english: "Three",italian: "Tre",german: "Drei"},"4": {english: "Four",italian: "quattro",german: "vier"}};function SetValues(MyName){this.getField("MyTextFieldEng").value = MyData[MyName].english;this.getField("MyTextFieldIta").value = MyData[MyName].italian;this.getField("MyTextFieldGer").value = MyData[MyName].german;}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I thought that script was just to load the initial values to the combo. How does it relate to copying the data from the combo to the text box?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

miQlo
Registered: Jul 13 2010
Posts: 44
No not TO the combo, i believe it works like something this (I've copied it from Thomp and this is my first time with scripts)

If the combo has the export value of "2" it goes to the "MyData" variable and looks at position "2" and populates the three text fields listed under the function "SetValues" with corresponding language.
(that explanation might be more confusing than informative)

I'll explain how it should work instead.
When I choose "Two" from the combo it should populate three fields with "Two" "Due" and "Zwei".
miQlo
Registered: Jul 13 2010
Posts: 44
I've found a solution, I don't know if its correct but it works.

I've removed the function from the document-level script, removed the script for the keystroke event and added this code into the calculate event for the combo box.
this.getField("MyTextFieldEng").value = MyData[this.getField("MyComboBox").value].english;
Which I think is the same thing as the function SetValues(MyName). This will only populate the English text field of course. However, it works yeij.

Thanks for all your support, I'll probably be back in a couple of minutes with my next problem.