Copy link to clipboard
Copied
I am working on creating a form filled document in Adobe Acrobat Pro 2020. I have a few fields that require a dropdown with two unique addresses for user to choose from. Currently the field runs the address accross the page and I'd like to to do a multi-line to make better use of space.
I've seen different keystroke scripts for multi-line addresses in discussions over the several years but nothing I've added under Dropdown Properties/Format/Custom Keystroke Script is working? Wondering if I have entered a wrong field in the script below? Should I be entering the addresses as part of the item under Options/Item?
Under General/Name I've entered "Location"
Under Options/Item I have the following Items:
Item: Illinois
Export Value: 0
Item: Henrietta
Export Value: 1
Commit selected value immediately is selected.
Under Dropdown Properties/Format/Custom/Custom Keystroke Script
// Custom Keystroke script for combo box
(function () {
if (!event.willCommit) {
// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "555 Illinois BLVD.\rNew York, NY 10013";
aAddr[1] = "201 Henrietta St.\rNew York, NY 10019";
// Get the export value of the selected item
var ex_val = event.changeEx;
// Get the corresponding address
var addr = aAddr[ex_val];
// Populate the text field with the address
getField("location").value = addr;
}
})();
The error message is indicating that there is no field named "location" on the form.
The comments indicate that "location" is the name of the text field that recieves the address.
Check the field names and put the correct text field name in the script.
Copy link to clipboard
Copied
Other than the closure function and a missing "this", the code looks good.
I would have written it like this:
// Custom Keystroke script for combo box
// Set up an array of addresses. \r = carriage return
var aAddr = ["555 Illinois BLVD.\rNew York, NY 10013","201 Henrietta St.\rNew York, NY 10019"];
if (!event.willCommit) {
// Get the corresponding address
var addr = aAddr[event.changeEx];
// Populate the text field with the address
this.getField("location").value = addr;
}
The first thing to do when code is not working is to look in the Console Window to see if any errors are reported.
Copy link to clipboard
Copied
Hi Thom,
I've attempted to enter your version of code and I'm still not getting the dropdown to populate with an address. See image #1 It remains the Item description under Options. See further below. I opened the console window with the script and the error I receive is in second image below. Did I copy your code incorrectly? First time doing anything with keystroke scripts.
Copy link to clipboard
Copied
The error message is indicating that there is no field named "location" on the form.
The comments indicate that "location" is the name of the text field that recieves the address.
Check the field names and put the correct text field name in the script.
Copy link to clipboard
Copied
The drop-down field will not be populated with the address, but another field will (a multi-line text field).
Dropdowns are not multiline fields, although you can technically show a multi-line value in them, but it's undocumented and not recommended.