Copy link to clipboard
Copied
Hello All,
I have zero experience in Acrobat Form with multiple selections and foray into drop-down list. Referring to Mr. Thom Parker's article of "Programming list and combo fields in Acrobat and LiveCycle forms - Part 1 of 2", I have learned from you a lot. The example file "ListProgramming_Part1_AcroForm.pdf" is exactly what I need.
I tried to export into .csv file in Excel and would like to display "item value" in the spreadsheet as opposed to "export value" from Drop-down List "Part" . For this purpose, I have googled and acquired some basic knowledge from JavaScript for Acrobat API Reference.
Based on the example file, I added the codes below extra into "Example1" document JavaScript, which contains scripts created.
function expPartValue() {
if(!event.willCommit){
var cRowName = event.target.name.split(".").shift();
var f = this.getField(cRowName + ".PartSelect");
var a = f.currentValueIndices;
console.println(f.getItemAt(a, false));
}
}
In order to test, calling “expPartValue()” function from a the Keystroke Event of "PartSelect" field, the results are displayed in the console window of JavaScript Debugger. Regardless it may be ok with me.(For sure, it is flawed.)
When I replaced "console.println(f.getItemAt(a, false));" with
"event.value = f.getItemAt(a, false);", it does meet the expectation.
May I ask a question about how I can get item value. I am wondering whether the codes are wrong. Any advices from you are highly appreciated.
Copy link to clipboard
Copied
So first, please keep you question simple and focused on a single topic. The more clear and concise the question, the better the answer.
You should also read these articles:
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
https://acrobatusers.com/tutorials/change_another_field/
Now, the keystroke and willCommit events are called when the field value is in transition. None of the actual field value properties have been changed. The "currentValueIndices" property contains the index for the current selection, not the selection just made by the user. Similarly, the "getItemAt()" function returns the item values for the current selection, not the one just made. The only way to get the new selection is through the event properties.
Both of these properties, the change value and the new export, are provided through the proper Keystroke event, i.e. when "event.willCommit" is false
You can find this information by consulting the Acrobat JavaScript Reference:
Here's a modification of your scirpt
function expPartValue() {
if(!event.willCommit){
console.println("Keystroke: Change=" + event.change + " Export=" + event.changeEx);
}
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
So first, please keep you question simple and focused on a single topic. The more clear and concise the question, the better the answer.
You should also read these articles:
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
https://acrobatusers.com/tutorials/change_another_field/
Now, the keystroke and willCommit events are called when the field value is in transition. None of the actual field value properties have been changed. The "currentValueIndices" property contains the index for the current selection, not the selection just made by the user. Similarly, the "getItemAt()" function returns the item values for the current selection, not the one just made. The only way to get the new selection is through the event properties.
Both of these properties, the change value and the new export, are provided through the proper Keystroke event, i.e. when "event.willCommit" is false
You can find this information by consulting the Acrobat JavaScript Reference:
Here's a modification of your scirpt
function expPartValue() {
if(!event.willCommit){
console.println("Keystroke: Change=" + event.change + " Export=" + event.changeEx);
}
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
That is great, Thom. Thanks a ton for your advices and help.
Copy link to clipboard
Copied
Exporting to a CSV is a different issue. First, a script in Acrobat cannot write directly to an external file that is not a PDF. A script can write to a PDF file attachment, but only in Acrobat Pro. The free reader is restricted.
But assuming that the user has Acrobat Pro, the best way to do this would be to add a button to the form labeled "Save to CSV", then write a button script to create the CSV file as an attachment.
Use the Acrobat JavaScript Reference early and often

