Skip to main content
Participant
January 6, 2020
Answered

Auto date/time field fill when another field is filled in

  • January 6, 2020
  • 1 reply
  • 5352 views

Per the title, I'm looking for a way to automatically add the date and time to a field at the moment another field is filled in.  I don't want to use stamps or signatures as i'd like to export these forms to excel in the future to log the data. Bit hard to explain but for example: User A enters initials in "IN1" field, as soon as they fill and exit the field, the date and time that the change was made is entered into a date/time field (ts1) to the right.  


I know this has to be done with a javascript, and I've got one that I believe should be working but I can't figure out how to get it running.  Script below:

 

// Declair Variables
var initials, timeStamp;

// Assign Variables
var initials = IN1
var timeStamp = ts1

if (timeStamp.value == null) {
if (initials.value != null) {
var d = Date(Date.now());
var ds = d.toString()
timestamp = ds.slice(1,24)
}
}

 

Thanks in advance!

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

Place the code for setting the timestamp into the Validate event script for the "Initails" field. 

Something like this

 

this.getField("ts1").value = util.printd("dd:mm:yyyy:HH:MM:ss",new Date);

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
January 6, 2020

Place the code for setting the timestamp into the Validate event script for the "Initails" field. 

Something like this

 

this.getField("ts1").value = util.printd("dd:mm:yyyy:HH:MM:ss",new Date);

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
NMPSGAuthor
Participant
January 14, 2020

That did the trick, thanks!!!