Use Acrobat JavaScript to Calculate PDF Order Form Costs
Question details
Calculate supply-period costs in a PDF order form based on client category and product selections.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- An order form needs separate prices for two-, four-, and eight-week supplies, with pricing that varies by product and client category.
- Observed behavior
- Each supply-period field should display the correct cost for the selected product and client category.
In Acrobat’s Prepare a Form tool, check the exact field names and the export values for each option in the Client_co-payment and Product drop-downs. Gather the pricing rules and identify the output fields for the two-, four-, and eight-week costs.
Add a custom calculation script to each cost field in Acrobat
Use this approach when the PDF must calculate costs automatically as users change their drop-down selections.
The actual product options, export values, prices, and output field names were not provided. Replace the placeholders with values from the form; do not use the example as a finished pricing table.
The template below stores the final cost for each supply period. Calculate those amounts from the applicable weekly or fixed-price rules before entering them.
Open the PDF in Acrobat and choose All tools > Prepare a form. Double-click Client_co-payment and Product, then check each field’s name and the option export values under Options.
In Prepare a form, double-click the two-week cost field. On the Calculate tab, select Custom calculation script and click Edit.
Paste this template into the JavaScript editor. Replace the product and client placeholders with actual export values, add an entry for every valid combination, and replace null with each final period cost: var weeks = '2'; var prices = { 'PRODUCT_EXPORT': { 'CLIENT_EXPORT': { '2': null, '4': null, '8': null } } }; var productField = this.getField('Product'); var clientField = this.getField('Client_co-payment'); var product = productField ? productField.valueAsString : ''; var client = clientField ? clientField.valueAsString : ''; var productPrices = Object.prototype.hasOwnProperty.call(prices, product) ? prices[product] : null; var clientPrices = productPrices && Object.prototype.hasOwnProperty.call(productPrices, client) ? productPrices[client] : null; var amount = clientPrices ? clientPrices[weeks] : null; event.value = typeof amount === 'number' && isFinite(amount) ? amount : '';
Open the Calculate tab for the four-week and eight-week output fields and add the same completed script to each. Change var weeks to '4' in the four-week field and '8' in the eight-week field.
Use each cost field’s Format tab to select a number or currency format. Exit form editing, change both drop-down selections, and verify all three costs against the pricing rules, including combinations with fixed prices.

Calculate Order Costs in WPS Spreadsheets
For a spreadsheet-based order workflow, use WPS Spreadsheets to calculate prices and export a completed order as a PDF. WPS Office is a free, lightweight alternative with a familiar interface and format compatibility for an easy transition from Microsoft Office. It does not replace Acrobat’s interactive PDF JavaScript calculations.

Frequently Asked Questions
Where do I find a drop-down option’s export value in Acrobat?
Choose All tools > Prepare a form, double-click the drop-down field, and inspect its options on the Options tab. Use the export value in the pricing table rather than assuming it matches the displayed label.
Why is a calculated cost field blank?
Check that the script’s field names and pricing-table keys exactly match the form’s field names and selected export values. In the provided template, an unmatched combination or a null price leaves the field blank.
Can I use different rules for weekly and fixed prices?
Yes. Work out the final cost for each product, client category, and supply period, then enter those amounts in the corresponding '2', '4', and '8' entries of the script’s pricing table.
Will the form calculate in every PDF viewer?
No. The viewer must support Acrobat form JavaScript. Open the finished PDF in the intended viewer and test the drop-down selections and calculated fields.




