Skip to main content
Inspiring
July 4, 2023
Answered

Prepopulating a field

  • July 4, 2023
  • 1 reply
  • 712 views

I have a form in which I want to prepopulate a field. Specifically load it with today's date. I have written a "document script" which does this. When the document loads, it works, but after doing a "reset form", it doesn't. What I find frustrating is that I have another form in which this works perfectly but I can't find the difference.

 

Any thoughts?

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

Here's a shorter script;

 

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

 

Since this is a document script, it only runs when the PDF is opened. For the field to automatically populate on a reset it would need to be a script on the reset button. 

 

1 reply

Thom Parker
Community Expert
Community Expert
July 4, 2023

You'd need to post the form so we could look at it.

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Jack157FAuthor
Inspiring
July 4, 2023

I'm a bit uncomfortable posting the entire form. Here is the field:

 

And here is the javascript:

 

var today = new Date();
var yyyy = today.getFullYear();
mm = today.getMonth() + 1; // Months start at 0!
dd = today.getDate();

if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;

var today = mm + '/' + dd + '/' + yyyy;
vsigdate=getField("Signature Date").value=today

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
July 4, 2023

Here's a shorter script;

 

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

 

Since this is a document script, it only runs when the PDF is opened. For the field to automatically populate on a reset it would need to be a script on the reset button. 

 

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