Skip to main content
Fiddling Orion
Inspiring
December 16, 2022
Answered

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

  • December 16, 2022
  • 1 reply
  • 931 views

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!

 

 

This topic has been closed for replies.
Correct answer Thom Parker

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

 

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
December 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Fiddling Orion
Inspiring
December 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;