Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need to auto generate text from two fields (first and last name) into another field

Explorer ,
Dec 16, 2022 Dec 16, 2022

Help! I tried a lot of various Javascript lines in different ways as actions and custom scripts, but not having much luck...

I am looking to combine the first and last name from earlier 2 earlier fields for a potential applicant, and apply it to a later part of the application. Also if possible, add a comma and then generate the current date as well. If that's too much, I can do that in a seperate field...but would be nice to get it all in one go. 

 

Thanks in advance!

 

 

TOPICS
Create PDFs , How to , JavaScript , PDF forms
749
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Dec 16, 2022 Dec 16, 2022

To help you out on this issue it would be helpful for you to provide the names of the first and last name fields.

But for the purposes of providing a script I'll assume they are "FirstName" and "LastName".

 

Place the following script into the custom calculation of the field where the combined name/date will be displayed. 

 

event.value = this.getField("FirstName").value + " " + this.getField("LastName").value + " , " + util.printd("mm/dd/yyyy", new Date());
 

 

 

You can learn more about scripting PDF forms here:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2022 Dec 16, 2022

To help you out on this issue it would be helpful for you to provide the names of the first and last name fields.

But for the purposes of providing a script I'll assume they are "FirstName" and "LastName".

 

Place the following script into the custom calculation of the field where the combined name/date will be displayed. 

 

event.value = this.getField("FirstName").value + " " + this.getField("LastName").value + " , " + util.printd("mm/dd/yyyy", new Date());
 

 

 

You can learn more about scripting PDF forms here:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2022 Dec 16, 2022

Thanks very much! That worked out perfectly. I was super close, heheh.

Question though: I modded this slightly to get the time added. But is there some way to get that time and date to be precisly when the applicant click on a connected checkbox to make it appear, or perhaps just refresh that triggers the day and time to be refreshed? This is the code in the check box that makes the other field appear, if that helps in any way:  

var nDisplay = event.target.isBoxChecked(0) ? display.visible : display.hidden;
this.getField("SigA").display = nDisplay;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2022 Dec 16, 2022
LATEST

Never mind on my last question Thom!

I just need to add calculateNow() to the script and done!

Thanks 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines