How to Map Quantities to Values Using JavaScript in PDF Forms
Question details
The user needs a custom script to configure a PDF form to output specific values in a calculation field based on the numerical quantity entered into another designated field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating dynamic and interactive PDF forms that evaluate user input to automatically populate corresponding tiered values or prices.
- Observed behavior
- The form must dynamically read the input from field B4 and output a mapped value (e.g., 1 to 10000, 2 to 9000) in a separate target field without altering the user's original input.
Ensure you have the proper PDF editing software installed, such as Adobe Acrobat Pro, that fully supports editing interactive form fields and inserting custom JavaScript calculations.
Apply a Custom JavaScript Calculation Script to the Output Field
Use a conditional if/else JavaScript statement in the output field's calculation properties to evaluate the input field and display the correctly mapped value.
To ensure the form functions correctly, the custom calculation script must be applied to the destination text field where you want the result to appear, not the input field. Applying it to the input field will cause a circular reference and overwrite the user's manual entry.
Open the PDF document in editing mode. Right-click the destination text field (the output field) and select 'Properties' from the context menu.
In the Text Field Properties dialog box, click on the 'Calculate' tab to view calculation options.
Select the 'Custom calculation script' radio button and click 'Edit'. Enter the following code: var q = Number(this.getField("B4").value); if (q == 0) event.value = 0; else if (q == 1) event.value = 10000; else if (q == 2) event.value = 9000; else if (q == 3) event.value = 8000; else if (q >= 4) event.value = 7000; else event.value = "";
Click 'OK' to close the JavaScript editor, then close the Properties dialog. Enter different values into field B4 to verify the output updates accordingly.

Create and Manage PDF Forms Easily with WPS Office
WPS Office offers a robust built-in PDF editor that allows you to effortlessly view, fill, and create interactive PDF forms without the steep learning curve of advanced software.
- 1. Open your PDF file: Launch WPS Office and open your existing PDF form document.
- 2. Access the Form tools: Navigate to the 'Form' tab located on the top ribbon menu to access the PDF form editing tools.
- 3. Insert text fields: Click the 'Text Field' tool to insert interactive input and data fields seamlessly into your document.
- 4. Manage field properties: Double-click the inserted field to configure its properties, adjust formatting, and finalize your interactive PDF form.

Frequently Asked Questions
Can I put the custom calculation script directly into the input field?
No, placing the custom calculation script in the input field will prevent users from entering data and can create a circular reference error. You must always apply the script to the target output field.
Why is my PDF custom calculation not updating automatically when I type?
Ensure that the calculation order is set correctly in your PDF form properties. Forms calculate fields in a specific sequence; if the output field is processed before the input field is finalized, the result may not update immediately.
What programming language is used for PDF form calculations?
PDF forms utilize JavaScript for custom calculations, logic flows, formatting, and validation scripts. These operations are executed through the Acrobat JavaScript API framework.
How do I reference a specific field's value in Acrobat JavaScript?
You can retrieve a specific field's input value by using the this.getField("FieldName").value method within your JavaScript code, replacing "FieldName" with the actual name of your target field.




