How to Clear a Price Field When Quantity is Deleted in Acrobat PDF
Question details
The user needs to use Acrobat JavaScript to automatically clear a Price field in a PDF form whenever the corresponding Quantity field is deleted, left empty, or set to zero.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Setting up advanced form field calculations and validations in an interactive PDF to ensure accurate pricing totals.
- Observed behavior
- Without a specific validation script, the Price field may retain an old value or display incorrectly when the user removes or zeroes out the Quantity field.
Make sure you are in the 'Prepare Form' mode in Adobe Acrobat and note down the exact field names for both your Quantity and Price text boxes, as JavaScript execution is case-sensitive.
Use a Custom Validation Script on the Quantity Field
Add a simple JavaScript code to the validation properties of the Quantity field so it instantly clears the Price field when left empty or set to zero.
Using a custom validation script directly on the field triggering the change (Quantity) ensures the most immediate update.
This script checks if the value is strictly an empty string or mathematically equates to zero, then targets the Price field to clear its contents.
In Adobe Acrobat, go to the 'Prepare Form' tool. Right-click your 'Quantity' text field and select 'Properties'.
Click on the 'Validate' tab at the top of the Text Field Properties dialog box.
Select the 'Run custom validation script' option, then click the 'Edit' button.
Type or paste the following code: if (event.value === "" || Number(event.value) === 0) { this.getField("Price").value = ""; }.
Click 'OK' and then 'Close'. Exit 'Prepare Form' mode and test by typing a number into the Quantity field, then deleting it to verify that the Price field clears.

Use a Custom Calculation Script on the Price Field
Alternatively, you can place a calculation script directly on the Price field to clear itself based on the Quantity field's status.
Edit and Manage PDF Forms Seamlessly with WPS Office
WPS Office provides a comprehensive PDF editor that lets you view, fill, and manage interactive PDF forms effortlessly. Whether you are handling documents with complex field calculations or basic text inputs, WPS PDF keeps you productive without the high subscription costs.
- 1. Open WPS Office: Launch the WPS Office application on your computer and open the WPS PDF tool.
- 2. Load Your PDF Form: Click 'Open' and select your interactive PDF file containing the calculation fields.
- 3. Fill in the Data: Click into the fields to start entering your data. The built-in PDF engine will process standard form calculations and logic automatically.
- 4. Save or Export: Once the form is filled out correctly, click 'Menu' and choose 'Save' or 'Export to PDF' to secure your final document data.

Frequently Asked Questions
Why is my PDF form not calculating automatically?
If fields are not updating, auto-calculation might be disabled. In Acrobat, go to Edit > Preferences > Forms, and ensure 'Automatically calculate field values' is checked. Additionally, verify your form's calculation order under Prepare Form > More > Clear Form > Calculation Order.
Can I use this JavaScript to clear multiple fields at once?
Yes. You can clear multiple fields by adding more lines to your validation script. For example: this.getField("Price").value = ""; this.getField("Tax").value = ""; this.getField("Total").value = "";
Will custom JavaScript calculations work on mobile PDF readers?
Support for PDF JavaScript varies greatly across mobile apps. While the official Adobe Acrobat Reader app for iOS and Android supports basic JavaScript calculations, many third-party PDF viewers do not execute custom validation scripts.




