How to Add Line Breaks and Conditional Text to Acrobat PDF Form Fields
Question details
The user wants to use Acrobat JavaScript to dynamically insert line breaks and compile summary text based on user selections from checkboxes and radio buttons in a PDF form.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where a summary text field updates automatically based on the options a user selects in other fields.
- Observed behavior
- The user needs the correct JavaScript syntax, specifically the proper newline escape sequence, to append conditional text and format it across multiple lines in a target form field.
Ensure you have access to the 'Prepare Form' tools in your PDF editor and verify that the target summary text field has the 'Multi-line' option enabled in its properties.
Use Acrobat JavaScript to Build Conditional Summary Text
Utilize standard JavaScript logic and the correct newline escape character to dynamically populate a summary text field based on form interactions.
When writing custom calculation scripts in PDF forms, it is essential to use the backslash escape sequence for a line break, rather than a forward slash. You can evaluate the state of checkboxes or radio buttons to conditionally concatenate strings.
Open your PDF document in your editor, navigate to the 'Prepare Form' tools, and locate the target summary text field.
Right-click the summary field, select 'Properties', navigate to the 'Calculate' tab, and choose the 'Custom calculation script' option.
Set up an initial string variable for your summary by typing: var s = "Summary:";
Check the values of your checkboxes and append text using the \n character. For example: if (this.getField("Checkbox1").valueAsString != "Off") { s += "\nCheckbox 1 Selected"; }
Assign your concatenated string variable to the field's event value by adding: event.value = s; at the end of your script, then click 'OK' to save.

Edit and Fill PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to read, edit, fill forms, and manage PDF documents seamlessly. It is an excellent, lightweight suite for handling everyday PDF tasks.
- 1. Open WPS Office: Launch the WPS Office application and open your PDF document.
- 2. Navigate to the Form tools: Click on the 'Form' tab on the top ribbon to interact with and fill out the PDF form fields.
- 3. Edit or fill your document: Use the provided tools to type into text fields, check boxes, or use the 'Edit' tab to modify standard PDF text and elements.

Frequently Asked Questions
Why are my \n line breaks not working in the PDF text field?
The target text field must have the 'Multi-line' option enabled in its properties. If it is unchecked, all text will remain forced onto a single line despite the JavaScript newline instruction.
How do I check if a PDF checkbox is selected using JavaScript?
You can check its valueAsString property. If the checkbox is unchecked, it usually returns 'Off'. For example, you can use the condition: if(this.getField('CheckboxName').valueAsString != 'Off').
Can I use /n for line breaks in PDF JavaScript?
No, /n uses a forward slash and will be treated as regular text by the script engine. You must use the backslash escape sequence \n to insert a proper newline character.




