How to Auto-Fill an Address from a Company Name in a PDF Form
Question details
The user needs a way to automatically populate an address text field whenever a specific company name is selected or typed into another field within an interactive PDF form.

- Product
- Device & OS
- not provided
- Scenario
- Creating or editing an interactive PDF form where data entry can be streamlined by linking related fields.
- Observed behavior
- The address field needs to dynamically update based on a mapping table linked to the company name field using custom scripts.
Ensure you have a PDF editing tool that supports custom JavaScript for forms, and compile a complete list of company names and their corresponding addresses before writing the script.
Add Custom JavaScript to the Form Fields
Use a custom calculation script to map company names to specific addresses so the address field updates automatically.
To achieve automatic population, you can add a simple JavaScript snippet to your PDF form. This script uses an object lookup or a switch statement to match the selected company to its address. When the 'Company Name' field changes, the calculation triggers and updates the 'Address' field accordingly.
Open your PDF form in edit mode. Ensure you have two distinct fields created: a dropdown or text field named 'CompanyName' and a text field named 'Address'.
Right-click on the 'Address' text field and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab within the Properties window. Select the option for 'Custom calculation script' and click the 'Edit' button.
Input a script that maps the companies to addresses. For example: var addrMap = {'Acme Corp': '123 Main St', 'Globex': '456 Oak Ave'}; var company = this.getField('CompanyName').value; event.value = addrMap[company] || '';
Click 'OK' to save the script, then close the Properties window. Switch to the form preview or viewing mode, and change the Company Name to verify that the Address field populates correctly.

Create and Edit Interactive PDF Forms with WPS PDF
WPS Office provides a comprehensive set of PDF tools, allowing you to easily create, edit, and manage interactive PDF forms without the complexity of heavy software.
- 1. Open your PDF: Launch WPS Office and open your existing PDF document or create a new one from scratch.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal interactive field options like Text Field, Check Box, and Combo Box.
- 3. Edit Field Properties: Double-click any inserted field to modify its properties, set exact field names, and adjust visual formatting to prepare for data entry.

Frequently Asked Questions
Why isn't the address field updating when I change the company name?
Ensure that JavaScript is enabled in your PDF reader's preferences. Additionally, verify that the field names in your JavaScript code perfectly match the actual names of your form fields, as they are case-sensitive.
Can I use a dropdown list for the company names instead of a text field?
Yes, using a dropdown (Combo Box) for the company name is highly recommended. It prevents user typos and ensures the selected value exactly matches the keys in your JavaScript mapping table.
How do I clear the address field if no company is selected?
In your JavaScript mapping, you should include a fallback condition. For instance, using `|| ''` at the end of your value assignment ensures that if the company name is blank or unrecognized, the address field automatically clears out.




