How to autofill date and time based on a previous input?

Community Beginner ,
Jun 25, 2018

Copy link to clipboard

Copied

Hello,

I would like to know how to automate date and time (military time) based on a previous input. Please refer to the image below.

So, I would like to automate it so that when the shift supervisor has filled out the signature field, both the date and time field will be automatically filled. How can I do that? Please help! 

sshift.PNG

TOPICS
Acrobat SDK and JavaScript, Windows

Views

159

Likes

Translate

Translate

Report

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

How to autofill date and time based on a previous input?

Community Beginner ,
Jun 25, 2018

Copy link to clipboard

Copied

Hello,

I would like to know how to automate date and time (military time) based on a previous input. Please refer to the image below.

So, I would like to automate it so that when the shift supervisor has filled out the signature field, both the date and time field will be automatically filled. How can I do that? Please help! 

sshift.PNG

TOPICS
Acrobat SDK and JavaScript, Windows

Views

160

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 25, 2018 0
Most Valuable Participant ,
Jun 25, 2018

Copy link to clipboard

Copied

What kind of field is your "signature" field? If it's a real Digital Signature then it will contain the current date and time automatically, although it doesn't look like it is. If it's just a text field you can use the field's custom validation script to populate the other fields.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 25, 2018 1
Community Beginner ,
Jun 26, 2018

Copy link to clipboard

Copied

try67

I was somehow able to get it to work using the following script on the "signature" field:

var timeField = this.getField("Time");
timeField.value = util.printd("HH:MM", new Date());

var dateField = this.getField("Date");
dateField.value = util.printd("mm/dd/yyyy", new Date());

However, the problem I have with this is code is that every time the signature field is simply clicked on, the date and time is updates automatically. Even without putting any information on the signature field, the data and time gets updated. I would like to make it so that some sort of information has to be in the "signature" field for the date and time to be update. And, I would like to make sure the date and time field stay fixed once the "signature" field has been filled. Because, as of now, simply clicking on the signature filed updates the date and time automatically.

So, for example:

          Once "John Doe" was put his initials in the signature field, the date and time will be automatically updates and will remain fixed. Only when ALL the information in the signature has been erased can be date and time field change.

is there a way I can do this?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 26, 2018 0
Most Valuable Participant ,
Jun 26, 2018

Copy link to clipboard

Copied

You're on the right path. I think you placed the code in an incorrect location, though. Move it to be the signature field's custom Validation script, and use this version of it:

var timeField = this.getField("Time");

var dateField = this.getField("Date");

if (event.value=="") {

    timeField.value = "";

    dateField.value = "";

} else {  

    timeField.value = util.printd("HH:MM", new Date());  

    dateField.value = util.printd("mm/dd/yyyy", new Date());

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 26, 2018 1
mbabu001 LATEST
Community Beginner ,
Jun 26, 2018

Copy link to clipboard

Copied

Wow, thank you very much. This is exactly what I needed.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 26, 2018 0