From name field to another name field
Copy link to clipboard
Copied
I have a form field which will be filled "Name and Last Name". The second page of the pdf I have another form field that needs to be filled only the last name of the first field.
For example:
Filed one: "John Doe"
Second fiiled: Dear Dr. Doe, and the rest of the copy.....
Can you plase Help...
Copy link to clipboard
Copied
You'll need a script to split the name into pieces.
Assuming the name of the field on the 2nd page is "LastName",put this code into the custom format script for the first field.
this.getField("LastName").value = event.value.split(/\s+/).pop();
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
You need to be careful doing that. Many people have multiple first names, or multiple last names, and guessing what a person's last name is could be problematic. I would let the users fill in their names separately and then combine them to a single field, instead.
Copy link to clipboard
Copied
Thank you, I will try this. But I am new to Scripting. Working sample of PDF would be really helpful for me. If you can.
I really appreciate your help.
Copy link to clipboard
Copied
Thank you so much for your reply. If you don't mind, I am attaching the link to a working demo file. Can you take a look and fix it.
Thanks again.
Nick-
Copy link to clipboard
Copied
Each field needs to have a unique name, for starters.
Copy link to clipboard
Copied
Yeah, I thought about writing something about the pitfalls of this technique, but it's too complicated for this thread. Better to just do it and see how it works. It always returns the last entry, even it it's "Jr", or "the 3rd". In my view anyone who includes post titles in their names deserves to be called Mr 3rd
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
It's not only "Mr. 3rd" that will have this problem. In many places multiple first names are common, as well as multiple last names, and there's really no 100%-proof way of distinguishing between them. It's not worth taking the risk of pissing off a bunch of people just for this small automation. Much better to do it the other way around, IMO.
Copy link to clipboard
Copied
I agree.
Use the Acrobat JavaScript Reference early and often

