add automated today's date to a form using javascript

What is the exact procedure in adding a text field that will generate today's date when the form is opened using javascript.


Kathleen Kaiser


2 Answers

Voted Best Answer

Supposing you have created a read only field called “todayDate” and formatted it as date, you need to create a document level JavaScript, using Adobe Acrobat Pro, to change the value of the field when the PDF is opened. In Acrobat XI Pro go to menu View -> Tools -> JavaScript:

enter image description here

Click on “Document JavaScripts” and add the following code:

enter image description here

function dateToday() {
    var d = new Date();
    f = this.getField("todayDate");
    f.value = d;
}

dateToday();

When the document is opened the dateToday() function is loaded and executed. If you want the “todayDate” field to be updated when the form is reset, you can call the dateToday() function in the Custom Calculation Script of the “todayDate” field.

enter image description here

enter image description here


By Almir R V Santos   

You might want to look at Example Acrobat JavaScripts by Chris Dahl.


George Kaiser   


Please specify a reason: