Skip to main content
Participant
May 11, 2017
Question

Current Date on Forms

  • May 11, 2017
  • 1 reply
  • 1145 views

Are there instructions somewhere to autopopulate the current date in a .pdf created form? I am a fairly new user to acrobat Pro XI. I see JavaScript text. Not sure where to type in or what settings to change. I appreciate anyone with patience to help out. Thank you!

This topic has been closed for replies.

1 reply

Inspiring
May 11, 2017

Example Acrobat JavaScripts has a simple sample document level script on how to do this.

A more extensive script that does not clear the date if the form is cleared follows:

// fill auto date field document level function;
function AutoDate(cFormat, cDateField)
{
var bChanged = false; // return value to indicate if date field updated or not;
var oDateTime = this.getField(cDateField); // get date field;
if(oDateTime.defaultValue == "")
{
  // update if field has not been fillen in;
  var d = new Date(); // get today's date object;
  var sDate =  util.printd(cFormat, d); // format date object to display string;
  oDateTime.defaultValue = sDate; // set default value;
  oDateTime.value = sDate; // set displayed value;
  bChanged = true;
}
return bChanged; // return result of function;
} // end AutoDate function;

var cFieldName = 'todaysDate';
var cDateFormat = 'mm/dd/yyyy';
var bUpdated = AutoDate(cDateFormat, cFieldName);
// additional code to show result of auto date function;
if(bUpdated == true) {
app.alert("Auto date field updated", 3, 0);
} else {
app.alert("Auto date field not updated", 3, 0);
}
// end Auto DAte field document level script;

This script uses the "default value" of the field to determine if the date field should be updated or not. If the form is edited, one just needs to clear the "Option" "Default value" to have date automatically update the next time the form is opened.