Skip navigation
TRG622
Currently Being Moderated

Inserting current time and date in a form

Feb 16, 2012 7:40 AM

Feel silly here, but I can't seem to find a way to insert form fields that will display currnet time and date, I see where it can be done for a digital signature, but that's not what I need. This is for a client sign in sheet. I want to know what date and time the form is printed, without having to manually enter that data. Thanks.

 
Replies
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Feb 16, 2012 8:01 AM   in reply to TRG622

    If you want to set a field to show the date/time whenthe document is opened, you can use the following code in a document-level script:

     

    getField("DATETIME").value = util.printd("mm/dd/yyyy HH:MM:ss"; new Date());

     

    where "DATETIME" is the name of the field.

     

    You can use the same code in the "Document Will Print" event to update it at the time of printing.

     

    For more information on the date format string options, see: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_A croJS.88.1251.html

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2012 8:09 AM   in reply to TRG622

    There's no Time object. Use new Date() in both instances.

     
    |
    Mark as:
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Feb 16, 2012 8:10 AM   in reply to TRG622

    That's right, but the last one needs to be changed to:

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2012 8:13 AM   in reply to TRG622

    Also, there must be a dot between the getField()-method and the value-property.

    AND, you need to use a comma inside printd, not a semi-colon.

     
    |
    Mark as:
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Feb 16, 2012 8:12 AM   in reply to TRG622

    Also, there was an additional typo, so the first needs to change to:

     

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

     

    Note the period just before the "value".

     
    |
    Mark as:
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Feb 16, 2012 8:50 AM   in reply to TRG622

    No, it should be placed either in a document-level JavaScript (Advanced > Document Processing > Document JavaScript (Acrobat 9), or Tools > JavaScript > Document JavaScript) outside of a funtion definition, or in the initial page's Page Open event.

     

    As mentioned, you can also place it in the "Document WIll Print" event if you want it to update at the time of printing. In Acrobat 9 you'd select "Advanced > Document Processing > Set Document Actions" and in Acrobat 10 you'd select "Tools > JavaScript > Set Document Actions".

     
    |
    Mark as:
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Feb 27, 2012 1:56 PM   in reply to TRG622

    That means you do not have a field named "Date". What is the name of the field you're working with? Case matters, so "Date" is not the same as "date", or anything else.

     
    |
    Mark as:
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Feb 27, 2012 2:42 PM   in reply to TRG622

    That code does't look like it was correctly copied, or else I made a few mistakes. It should be:

     

    // Mouse up script for check box
    (function () {
    
        // Get a reference to the text field
        var f = getField("text");
    
        // Set the value of the text field
        if (event.target.value !== "Off") {
            f.value = util.printd("mm/dd/yyy", newDate());
        } else {
            f.value = "";
        }
    })();
    

     

    There would have to be a text field named "text" for this to work.

     
    |
    Mark as:
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Feb 27, 2012 2:57 PM   in reply to TRG622

    There is supposed to be a space between "new" and "Date". If that doesn't fix it, I'll be happy to post a working sample.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 10:07 AM   in reply to George Johnson

    Hello: I'm new to Adobe Foms and I'm using Adobe Pro X.

     

    I'd like to have the current date inserted when the form opens. I inserted the code below in the Document Javascript section of Adobe. When I open the form nothing happens. I'd appreciate any assistance you can give.

     

    function Current_Date()

    {getField(Prepared_Date).value=util.printd("mm/dd/yy",new date())

    }

     
    |
    Mark as:
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    Jun 9, 2012 1:05 PM   in reply to stburden77

    It should not be a function, so the code can be just:

     

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

     

     

    Note the other corrections as well.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 4:28 PM   in reply to George Johnson

    Thanks George, that did it.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points