Fix Adobe Acrobat PDF Form JavaScript Errors from Spaces in Property Names
Question details
Use a combo-box value containing spaces as a JavaScript object property in an Acrobat PDF form without a syntax error.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form script uses a department selected in a combo box to look up address information in a JavaScript object.
- Observed behavior
- An unquoted property name containing spaces can trigger a missing-colon syntax error.
Open the PDF in Adobe Acrobat and identify the combo-box field name and the script that defines or accesses the object. Check the combo box's export values, since the script must use the value returned by the field.
Quote property names and look up the combo-box value with brackets
Use this fix when a JavaScript object key contains spaces or comes from a combo-box selection.
In Acrobat, open Prepare a form, select the relevant field, and open its Properties. Find the JavaScript under the field's Actions, Validate, or Calculate tab and select Edit.
In the script editor, put the entire property name in quotation marks when defining the object: var DeptData = {"CSS Frogner": {adresse: "Frederik Stangs Gate 4", poststed: "0272 Oslo"}};
In the same script, or wherever DeptData is available, retrieve the selection with var key = this.getField("Department").valueAsString; and look it up with var dept = DeptData[key];. Replace Department with the actual combo-box field name.
Close the script editor, save the PDF, and select the corresponding combo-box option. Confirm that its returned value exactly matches the quoted object key, including spaces and capitalization.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Microsoft Office files. It can help you migrate everyday document workflows, but it does not fix JavaScript in an Acrobat form.

Frequently Asked Questions
Why does a property name with spaces cause a missing-colon error?
In an object literal, a property name containing spaces must be quoted. Write {"CSS Frogner": value}, not {CSS Frogner: value}.
How do I use a combo-box selection to access an object property?
Read the field value with this.getField("Department").valueAsString, replacing Department with your field name. Then use bracket notation, such as DeptData[key], to look up that value.
Why does the lookup return undefined after I fix the syntax?
Check that the combo box's returned value exactly matches an object key, including capitalization and spaces. If the option has an export value, use that value as the key rather than assuming the displayed label is returned.
Where can I edit a form field's JavaScript in Acrobat?
Open Prepare a form, select the field, and open Properties. Depending on the script, look under Actions, Validate, or Calculate and select Edit.




