How to Insert PDF Form Field Values into Text Using JavaScript
Question details
The user wants to dynamically display the value of one PDF form field within the text of another field using JavaScript.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where a custom message automatically updates based on user input in another field, such as an organization name.
- Observed behavior
- The user needs the correct JavaScript calculation script to fetch and concatenate the source field value into the destination field's text.
Ensure your PDF editing software supports form field calculations and JavaScript. Make sure you have the exact name of the source field you wish to reference before editing the destination field's properties.
Add a Custom Calculation Script to the Destination Field
Use a simple JavaScript snippet in the destination text field's properties to automatically fetch and display the value from the source field.
By utilizing the custom calculation script feature in your PDF editor, you can dynamically pull data from one field and embed it into a text string in another field. This is highly useful for generating personalized messages or automated summaries within a form.
Open your PDF form in edit mode, right-click the destination text field where you want the message to appear, and select 'Properties'.
In the Properties dialog box, click on the 'Calculate' tab to view the calculation options for the field.
Select the option for 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor.
Type the following code: event.value = "At " + this.getField("IOrgName").valueAsString + " we believe..."; Make sure to replace "IOrgName" with the exact name of your source field.
Click 'OK' to save the script, close the properties window, and test the form by typing a value into the source field to see it update in the destination field.

Manage and Edit PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to view, fill, and manage interactive PDF forms effortlessly. It is a lightweight and cost-effective alternative for your daily document needs.
- 1. Download WPS Office: Download and install WPS Office on your computer or mobile device.
- 2. Open the PDF Form: Launch WPS PDF and open your interactive PDF form document.
- 3. Fill the Form Fields: Click on the highlighted form fields to directly input your text, numbers, or data.
- 4. Save or Export: Once completed, save the filled PDF or export it to share with others.

Frequently Asked Questions
Why is my destination PDF form field not updating automatically?
The destination field might not be set to calculate automatically. Check your PDF editor's preferences or form settings to ensure automatic field calculation is enabled. Also, verify that the source field name in your JavaScript exactly matches the actual field name, as it is case-sensitive.
Can I concatenate multiple form fields into one text field?
Yes, you can reference multiple fields in your JavaScript calculation script. For example, you can use: event.value = this.getField("Field1").valueAsString + " " + this.getField("Field2").valueAsString; to combine two fields with a space in between.
Does WPS PDF support JavaScript for PDF form calculations?
While WPS PDF excels at viewing, filling, and editing standard PDF forms, advanced JavaScript form creation and calculation authoring may require specific professional-grade PDF authoring tools. However, forms pre-configured with standard calculation scripts can often be filled out and will execute properly in WPS PDF.
How do I hide the destination text if the source field is empty?
You can add an 'if' statement to your custom calculation script to check if the source field is empty. For example: if (this.getField("IOrgName").valueAsString == "") { event.value = ""; } else { event.value = "At " + this.getField("IOrgName").valueAsString + " we believe..."; }




