Combine Values from Spawned PDF Pages into a Multiline Text Field
Question details
The user needs to extract and combine Street_No and Street field values from spawned PDF pages into a single multiline text field, properly formatted with spaces and line breaks.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating or editing interactive PDF forms that use JavaScript to dynamically gather and summarize data from spawned template pages.
- Observed behavior
- The current calculation script joins street names without spaces or line breaks, and contains improper loop initialization syntax.
Ensure that your target PDF form field has the 'Multi-line' property enabled, and verify that you have access to edit the custom JavaScript calculation scripts within the form.
Use Correct JavaScript Loop Syntax and Line Breaks
Apply a numeric index for your loop and use the carriage return character to format the concatenated values with spaces and line breaks.
To properly format the combined data, you must ensure your JavaScript loop is initialized correctly as a number rather than an empty string. Additionally, explicitly adding a space character and a carriage return will correctly format the output into multiple lines.
Open the custom calculation script for your summary field. Locate the loop initialization and change it from an empty string to a zero: for(var i=0; i<this.numFields; i++).
Before or within your loop, define a variable for the carriage return by typing: var newLine = "\r";
Update your field combination logic to insert a space between the street number and name, and append the line break at the end. For example: nStreet += streetNumber + " " + streetName + newLine;
Ensure the concatenated string is correctly assigned to the value of your destination multiline text field.

Use Hidden Fields for Pre-Combination
Simplify your main calculation script by using a hidden field on each spawned page to pre-combine the street number and street name.
Create and Edit PDF Forms Easily with WPS Office
WPS Office features a robust PDF editor that simplifies the creation and management of interactive form fields. You can easily add multiline text boxes, configure field properties, and manage form calculations without complex coding.
- 1. Open your PDF file: Launch WPS Office and open your existing PDF document or create a new one.
- 2. Access form tools: Navigate to the 'Form' tab located in the top ribbon menu to view all interactive elements.
- 3. Insert a text field: Click on 'Text Field' and drag your cursor on the document to draw the input box.
- 4. Enable multiline input: Double-click the inserted text field to open Properties, go to the Options tab, and check the 'Multi-line' setting.
- 5. Save and deploy: Save your PDF document. The form is now ready for users to enter formatted, multiline data.

Frequently Asked Questions
Why is my PDF text field not showing multiple lines despite adding line breaks?
If your text appears on a single continuous line, you need to enable the 'Multi-line' property for that field. Right-click the text field, go to Properties, select the Options tab, and check the 'Multi-line' box.
What is the correct JavaScript character for a line break in PDF forms?
In PDF form JavaScript, you should use the carriage return character `\r` or the newline character `\n` within your string concatenation to insert a line break into a multiline text field.
How do I loop through form fields correctly in PDF JavaScript?
Ensure you initialize your loop variable as a number (e.g., `var i = 0`) rather than an empty string (`var i = ""`). A standard `for` loop written as `for(var i = 0; i < this.numFields; i++)` will correctly iterate through all fields in the document.




