Other PDF Issues

How to Convert Numbers to Months, Weeks, and Days in Adobe Acrobat using JavaScript

John WilsonJohn Wilson Nov 5, 2026 869 views

Question details

The user needs a method to map numeric inputs ranging from 1 to 84 into specific duration labels (such as '1 Week' or '2 Months') within a PDF form field.

How to Convert Numbers to Duration using Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF form where users input a numerical value that must automatically be validated and converted into a readable time duration format.
Observed behavior
The form field currently accepts raw numbers but requires custom rules to restrict inputs strictly to the 1-84 range and swap those numbers for descriptive text strings based on defined thresholds.
Before you start

Ensure you have Adobe Acrobat Pro or an advanced PDF editor that supports adding custom JavaScript to form fields. It is highly recommended to save a backup copy of your PDF before applying new scripts.

Solution 1Recommended

Apply Custom Keystroke and Validation Scripts

Use a custom keystroke script to restrict user input to numbers between 1 and 84, followed by a validation script to assign the correct duration label based on the input.

This solution requires configuring two separate scripts in the properties of your PDF form field. The keystroke script leverages a regular expression to evaluate each character as it is typed, ensuring only valid numbers from 1 to 84 are accepted. The validation script then runs when the input is committed, utilizing conditional if-else statements to replace the numerical value with the corresponding duration text.

1
Open Field Properties

Open your PDF document in Form Editing mode. Right-click the target text field you want to modify and select Properties from the context menu.

2
Add the Keystroke Script

Go to the Format tab and choose 'Custom' from the Select format category dropdown list. Click the 'Edit' button next to 'Custom Keystroke Script' and enter the regex script provided to evaluate event.change and event.value, ensuring the input stays strictly within the 1-84 limit.

3
Add the Validation Script

Click the 'Edit' button next to 'Custom Validation Script'. Enter the if-else logic script that assigns specific string values to event.value based on numeric ranges (e.g., if event.value < 8, event.value = '1 Week').

4
Save and Test

Click OK to save the scripts, then close the Properties dialog. Exit form editing mode and type a number like '40' into the field to verify it correctly converts to '1 Month + 1 Week + Daily'.

Apply Custom Keystroke and Validation Scripts
Script Formatting: Ensure that your custom validation script covers all potential numeric ranges without overlapping conditions, utilizing strict 'else if' statements for accuracy.

Design Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive suite of PDF tools, allowing you to seamlessly create, edit, and manage interactive forms without relying on heavy, expensive software.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF editor.
  2. 2. Access Form Tools: Navigate to the Form tab on the top ribbon to view all available interactive form controls.
  3. 3. Insert a Text Field: Click on 'Text Field' and draw the input box on your document where you want the user to enter data.
  4. 4. Configure Field Properties: Right-click the newly created text field and select Properties to adjust formatting, appearance, and basic behaviors.
Easily insert text fields, checkboxes, and drop-down menusHighly compatible with standard interactive PDF formatsLightweight design for fast PDF rendering and processing
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Acrobat JavaScript form field not update immediately while typing?

Keystroke scripts evaluate data as it is typed, but validation scripts typically trigger only after the field loses focus or the value is explicitly committed (such as pressing Enter). Ensure you complete the input to see the text conversion.

Can I customize the duration labels in the validation script?

Yes, you can freely modify the text strings inside the quotation marks in your validation script. For instance, you can change '1 Week' to '7 Days' to better match your specific project or regional requirements.

Will these JavaScript form conversions work on mobile PDF readers?

JavaScript support varies widely across mobile PDF applications. While these scripts function reliably on desktop versions of Adobe Acrobat and standard PDF editors, many mobile apps do not fully support custom validation or keystroke scripts.