PDF Editing Issues

How to Clear a Price Field When Quantity is Deleted in Acrobat PDF

Jason MillerJason Miller Nov 2, 2026 869 views

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.

How to Clear a Price Field When Quantity is Deleted in Acrobat PDF
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Form Properties

In Adobe Acrobat, go to the 'Prepare Form' tool. Right-click your 'Quantity' text field and select 'Properties'.

2
Navigate to the Validate Tab

Click on the 'Validate' tab at the top of the Text Field Properties dialog box.

3
Add Custom Validation Script

Select the 'Run custom validation script' option, then click the 'Edit' button.

4
Enter the JavaScript Code

Type or paste the following code: if (event.value === "" || Number(event.value) === 0) { this.getField("Price").value = ""; }.

5
Apply and Test

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 Validation Script on the Quantity Field
Match Field Names Exactly: Ensure you replace 'Price' in the script with the exact name of the target field in your specific PDF form. If your field is named 'Price_Row1', the script must read this.getField("Price_Row1").
Advanced PDF Tools

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. 1. Open WPS Office: Launch the WPS Office application on your computer and open the WPS PDF tool.
  2. 2. Load Your PDF Form: Click 'Open' and select your interactive PDF file containing the calculation fields.
  3. 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. 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.
Seamlessly open and fill interactive PDF forms with auto-calculations.Fully compatible with standard Adobe PDF formatting and field logic.All-in-one software suite integrating Word, Excel, PowerPoint, and PDF editing.Lightweight and user-friendly interface for fast document processing.
QA img-9

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.