How to Append Dates to Multiline PDF Text Fields using JavaScript
Question details
The user needs to configure an interactive PDF form button to append a selected date into a read-only multiline history text area.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating or editing an interactive PDF form that requires logging history or recording multiple entries chronologically.
- Observed behavior
- Requires a JavaScript solution triggered by a button click that fetches a date value and appends it to a new line in a target text field.
Ensure you have a PDF editing software that supports the creation of interactive form fields and the execution of custom JavaScript actions.
Use JavaScript on a Button's Mouse Up Event
Add a custom JavaScript code to an 'Add' button to fetch the date and append it to your multiline text field.
This method requires setting the destination text field to accept multiple lines of text and configuring a button to run a script when clicked. It is ideal for creating history logs or tracking updates within a single PDF document.
Right-click your target text field (e.g., 'Text1') and access its Properties. Navigate to the Options tab and check the 'Multiline' box.
Right-click your 'Add' button, open its Properties, and go to the Actions tab.
Select 'Mouse Up' from the Select Trigger dropdown menu, choose 'Run a JavaScript' from the Select Action menu, and click 'Add'.
In the JavaScript Editor, enter the following code: var s = this.getField('Date1').valueAsString; if (s != '') this.getField('Text1').value += s + '\n'; Then click OK.
Save and close the properties window. Switch to the hand tool or preview mode and click the button to ensure the date appends correctly.

Create and Edit Interactive PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, allowing you to easily insert form fields, configure properties, and manage interactive elements for your document workflows.
- 1. Download and Install: Download and install WPS Office from the official website.
- 2. Open Your PDF: Launch the WPS PDF tool and open your target PDF document.
- 3. Navigate to Form Tools: Go to the Form tab on the top ribbon to access tools for adding text fields, buttons, and configuring properties.

Frequently Asked Questions
Why isn't the text appearing on a new line in the PDF text field?
This usually happens if the target text field does not have the 'Multiline' property enabled. Right-click the field, go to Properties, select the Options tab, and check 'Multiline'.
Can I append other field values besides dates using this JavaScript?
Yes. You can modify the 'this.getField("Date1").valueAsString' portion of the script to reference the name of any other text, dropdown, or choice field in your PDF form.
Are JavaScript field names in PDF forms case-sensitive?
Yes, JavaScript is case-sensitive. Ensure that the field names in your script exactly match the capitalization used in the form field properties.




