Skip to main content
Participating Frequently
December 3, 2010
Answered

Set Text Field Default Value Current Date

  • December 3, 2010
  • 1 reply
  • 43722 views

Thanks for taking the time to read my question.

I can't seem to figure out how to set a Tex Fields default value to the current date. Is there a way to do this?

Thanks,

Brad

    This topic has been closed for replies.
    Correct answer George_Johnson

    I just put

    var f = this.getField("Today");

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

    In the Custom calculation script: field under the Calculate tab for the properties for the text field and it seems to work now... Is that the best way to do it?

    Brad


    No, because the script will only get triggered when some other field value changes. It will not update when the document is opened until the user changes some field value.

    1 reply

    Inspiring
    December 3, 2010

    Do you want the date updated every time the document is opened, or something else?

    Participating Frequently
    December 3, 2010

    Sorry I thought everyone could read my mind.... lol . When the doc is opened, place today's date in the "TodaysDate" field.

    I'm continuing to search the interweb and I'm thinking about doing something with the Calculate on the text field's properties??

    Brad

    Inspiring
    December 3, 2010

    Just set the value of the field directly. Place the following code in a document-level JavaScript, outside of a function definition. It will execute every time the document is opened:

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

    You can use whatever format you want. More details here: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html