How to Automatically Increase a Number in a PDF Form
Question details
The user wants to automatically generate or increment a sequential protocol number in a PDF form when it is opened, completed, or printed based on specific conditions.

- Product
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF protocol form that automatically tracks and increments protocol numbers.
- Observed behavior
- Currently, the form fields require manual entry of the protocol number, but the goal is to use conditional logic or JavaScript to automate this increment based on user input.
Ensure you have a PDF editor that supports JavaScript calculations for form fields, and identify the exact field names (e.g., 'fill_8') you plan to reference in your script.
Use JavaScript to Calculate and Increase Field Values
Apply a custom calculation script to the target text field to automatically update its value based on another field's input.
By configuring a custom calculation script within the properties of a specific PDF form field, you can set up conditional logic. For example, the script can check if a user has entered data into 'fill_8' and then automatically update 'fill_20' with a higher number.
Open your PDF document in a compatible PDF editor, switch to the Form editing mode, and locate the field where you want the protocol number to appear.
Right-click the target field (e.g., the protocol number field) and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties dialog box, select 'Custom calculation script', and click the 'Edit' button.
Enter your conditional JavaScript logic. For example: var C = this.getField("fill_8").value; event.value = C > 1 ? 20 : 12;
Click 'OK' to save your script, close the Properties dialog, and test the form by entering a value greater than 1 into 'fill_8' to see if the target field updates automatically.

Create and Edit Advanced PDF Forms with WPS Office
WPS Office provides comprehensive PDF editing tools, allowing you to easily create interactive forms, add text fields, configure field properties, and manage document workflows efficiently without needing complex software.
- 1. Download and open WPS Office: Launch WPS Office on your device and click on the 'PDF' tab from the main interface.
- 2. Open your PDF document: Open the PDF file you wish to edit and navigate to the 'Form' tab in the top ribbon.
- 3. Insert form fields: Use the available form tools to add text fields, checkboxes, dropdowns, or buttons to your document layout.
- 4. Configure field properties: Right-click any newly added field to access its 'Properties', where you can set up formatting, appearance, and basic input rules.

Frequently Asked Questions
Why isn't my JavaScript calculation working in the PDF?
Ensure that the field names used in your script match exactly with the names in your form, including case sensitivity. Additionally, check that JavaScript is enabled in your PDF reader's preferences and that there are no syntax errors in your code.
Can a PDF automatically remember the last printed number?
By default, a standard PDF cannot permanently remember values between different user sessions once it is closed unless the document itself is saved after the number changes. To maintain a strict running sequence across multiple print jobs by different users, you typically need to connect the form to an external database.
How do I trigger a script right before printing the PDF?
You can use document-level JavaScript and attach a script to the 'Will Print' event. Go to your PDF editor's Document Actions or JavaScript settings, select 'Document Will Print', and enter the code needed to update the specific field right before the print dialogue opens.




