Copy link to clipboard
Copied
I have several text fields where names and addresses are typed into Names are typed into fields named IP1, IP2, IP3, etc. Addresses are typed into fields named IP1Address1, IP1Address2, IP2Address1, IP2Address2, etc. For example, the following information is typed into these text fields:
Alan Adams 111 Alto Avenue Atlanta, GA 11111
Bob Brenson 222 Bando Blvd Birminghame, AL 22222
Charlie Chapman 333 Connie Court Cleveland, OH 33333
On another page of the pdf file, names can be typed into other text fields. These text fields are named Name1, Name2, Name3, etc. After these text fields, there are text fields named Name1Address1, Name1Address2, Name2Address1, Name2Address2, etc. for addresses.
If the name Alan Adams is typed into Name1, I would like Name1Address1 to populate with Alan's street address and Name1Address2 to populate with Alan's city, state ZIP. If Bob's name is typed in Name1, I would like Name1Address1 to populate with Bob's street address and Name1Address2 to populate with Bob's city, state ZIP. Is this possible? Thanks.
Copy link to clipboard
Copied
- I made some adjustments to the code and how it is called. It now takes two parameters, one for the row number and one for the address field number. See the first two rows in the attached file.
- There are errors in the calculation code elsewhere in your file that could be interfering with this script. You need to solve them.
Copy link to clipboard
Copied
Yes, but you first need to think how it should work, exactly. Let's say the user changes the address entered for "Alan Adams" on the first page. Should that automatically carry over to the other page, if that name is selected there?
And should they be able to overwrite that value and enter a different address, if they wanted to? What if the name they enter on the second page doesn't match any name on the first one? etc.
Copy link to clipboard
Copied
Good points. If the user changes the address for Allan Adams on the first page, I would like it to automatically carry over to the other page.
I do not need to provide for overwrites to enter a different address. In my case, the names entered on the second page will only come from the names entered on the first page.
Copy link to clipboard
Copied
OK, in that case you can use something like this code as the custom calculation script for "Name1Address1".
event.value = "";
var name = this.getField("Name1").valueAsString;
if (name!="") {
for (var i=1; i<=3; i++) {
if (this.getField("IP"+i).valueAsString==name) {
event.value = this.getField("IP"+i+"Address1").valueAsString;
break;
}
}
}
You just need to adjust the field names in the code to use it for the other fields, too.
Copy link to clipboard
Copied
That works. Thank you.
What adjustments would I make to the script for another section of my pdf that uses the following names for the text fields on the first page:
IP1 name
IP1 address1
IP1 address2
And on the next page:
IP1 nameAOS
IP1 address1AOS
IP1 address2AOS
Please note the space after IP1 on all text field names. Thanks.
Copy link to clipboard
Copied
So the value of "IP1 address1" should be copied to "IP1 address1AOS" if "IP1 nameAOS" is the same as "IP1 name"?
Copy link to clipboard
Copied
Yes, that is correct.
Copy link to clipboard
Copied
And how many "IPX name" fields are there?
Copy link to clipboard
Copied
25
Copy link to clipboard
Copied
Place this code as a doc-level script:
function copyAddress(rowNumber) {
event.value = "";
var maxFields = 25;
var name = this.getField("IP"+rowNumber+" nameAOS").valueAsString;
if (name!="") {
for (var i=1; i<=maxFields; i++) {
if (this.getField("IP"+i+" name").valueAsString==name) {
event.value = this.getField("IP"+i+" address"+rowNumber).valueAsString;
break;
}
}
}
}
Then call it from the Calculation events of the address fields, like this:
// from IP1 address1AOS
copyAddress(1);
// from IP1 address2AOS
copyAddress(2);
etc.
Copy link to clipboard
Copied
I must be doing something wrong. I placed the initial code as a doc-level script. I then placed
copyAddress(1);
in the Custom Calculation Script of first address box and
copyAddress(2);
in the Custom Calculation Script of the second address box.
The first address box populates as expected. The second address box does not populate at all no matter what I type in the IP1 nameAOS field.
Also, I'm not sure what to enter in the IP2 address1AOS, IP2 address2AOS, etc. fields.
Thanks for bearing with me.
Copy link to clipboard
Copied
It will be easier if you could share the file, either publicly or privately.
Copy link to clipboard
Copied
It's a large file - 179 pages. I will try to extract the relevant pages, of which I think there are just two.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
My file contains an attachment page for the Affidavit of Service with name and address boxes for 5-25. I did not include that. The doc-level script is named Affidavit of Service.
Copy link to clipboard
Copied
- I made some adjustments to the code and how it is called. It now takes two parameters, one for the row number and one for the address field number. See the first two rows in the attached file.
- There are errors in the calculation code elsewhere in your file that could be interfering with this script. You need to solve them.
Copy link to clipboard
Copied
Thank you! Everything appears to be working as expected. I will look for the errors in the calculation code, but I wonder if it has anything to do with me extracting two pages from a larger file.
If I wanted to change the IP1 nameAOS, IP2 nameAOS, etc. text fields to dropdown boxes, would it be possible to have these dropdown boxes populate with the text entered in the IP1 name, IP2 name, etc. text fields so the user could select the name from the dropdown list rather than type them in (and risk making a typo in the process)?
Copy link to clipboard
Copied
Yes, but updating them will be tricky. I would recommend using a button to do it, instead of an automatic calculation.
Copy link to clipboard
Copied
I have not worked with buttons before. Do you have an article or snippet of code to set me in the right direction? Thank you.
Copy link to clipboard
Copied
What you need to do is collect the values to an array, and then apply it to the drop-down(s) using the setItems method. Just be aware that it will override any values they already selected and return the field to its default value (which is the first item in the list).
For example:
function copyNames() {
var maxFields = 25;
var names = [""];
for (var i=1; i<=maxFields; i++) {
var name = this.getField("IP"+i+" name").valueAsString;
if (name!+"") names.push(name);
}
}
this.getField("IP1 nameAOS").setItems(names);
this.getField("IP2 nameAOS").setItems(names);
this.getField("IP3 nameAOS").setItems(names);
this.getField("IP4 nameAOS").setItems(names);
}
Then you just call copyNames(); from the Mouse Up event of the button.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now