How to Populate a PDF Dollar Amount from a Drop-Down Selection
Question details
The user wants to automatically populate a marketing budget field based on a colleague selected from a drop-down list using PDF JavaScript, but needs to know the correct syntax for handling currency.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where selecting an option from a drop-down menu automatically fills another text field with a specific dollar amount.
- Observed behavior
- The JavaScript code fails to populate the field correctly when dollar signs or commas are included directly in the script's numeric values.
Ensure your PDF editor supports form field creation and JavaScript execution, and verify that you have access to the form editing or 'Prepare Form' tools.
Use Raw Numeric Values and Apply Field Formatting
To prevent JavaScript errors, assign raw numeric values in your code and use the built-in field formatting options to display the currency symbols.
When writing JavaScript for PDF forms, including symbols like '$' or commas turns the numeric value into a text string. This can break calculations and auto-population scripts. The best practice is to pass a pure number in the code and let the PDF viewer handle the visual formatting.
Open your drop-down list's action script and remove any dollar signs or commas from the assigned values. For example, change your code from event.value = "$1,000"; to event.value = 1000;.
Right-click the text field where the marketing budget will be displayed (the target field) and select 'Properties' from the context menu.
Navigate to the 'Format' tab in the Properties window. Select 'Number' from the format category drop-down, then choose the Dollar symbol and set the separator style to include commas.
Manage PDF Forms Easily with WPS PDF
WPS PDF offers an intuitive interface for filling, creating, and managing interactive PDF forms. Whether you are handling budgets, invoices, or surveys, WPS Office makes document management seamless.
- 1. Open WPS Office: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form fields and interactive elements.
- 3. Edit Field Properties: Double-click any form field to adjust its properties, appearance, and formatting options.
- 4. Save the Document: Once your form is configured, click 'Save' to preserve the interactive fields and formatting.

Frequently Asked Questions
Why does my PDF JavaScript fail when I add a dollar sign?
PDF JavaScript treats values containing dollar signs and commas as text strings rather than numbers. For calculations or value assignments to work correctly, you must use raw numbers (like 1000) and apply currency formatting directly to the field's properties.
How do I format a PDF text field to show currency automatically?
Right-click the target text field, select Properties, and go to the Format tab. Choose the Number category, then select your desired currency symbol and decimal places.
Can I use JavaScript to calculate totals from multiple drop-down selections?
Yes, you can write a custom calculation script in the target field's properties. This script can retrieve the raw numeric values of multiple drop-down fields and add them together before displaying the formatted total.




