Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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_AcroJS.88.1251.html
Copy link to clipboard
Copied
OK, thanks. And if I wanted to break out the date and time into two seperate fields would that be
getField("Date") value = util.printd("mm/dd/yyyy", new Date())
getField("Time") value = util.printd("HH:MM)"; new Time())
Copy link to clipboard
Copied
There's no Time object. Use new Date() in both instances.
Copy link to clipboard
Copied
That's right, but the last one needs to be changed to:
getField("Time").value = util.printd("HH:MM)"; new Date())
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
so this code would be inserted in the Actions tab in the Properties window of the form field? Thanks again. I'm brand new to Acrobat and this is the very first form I'm creating with it.
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
ok, tried that and here's the error I get:
TypeError: getField ("Date") is null
1: Doc:Will Print
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Actualy, looking around the web I found another Adobe forum where you answered another person's question about using a check box to populate a text field with the date, which is actually what I really need, as I want to be able to print the form with or without the date and time appearing. Here's the script you posted:
// 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 = " ";
}
} ) ();
I copied and pasted the code straight into the mouse up event for the check box, and then changed the text box name to the actuall name of the date text field, and the error I get is "too much recursion".
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
right, the field is actually called "Date". copied and pasted straight off what you just posted and the error i get now is 'newDate is not defined'. BTW thanks so much for taking the time to help with this.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Works like a champ for both the date and time fields. Thanks for all your help!
Copy link to clipboard
Copied
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())
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks George, that did it.
Copy link to clipboard
Copied
Mouse over the date field:
var d = new Date();
var f = this.getField("YourFieldNameHere");
if (f.value!=d.value)
f.value = util.printd ("dd/mm/yyyy", d)
Copy link to clipboard
Copied
This question is more than 8 years old, and was already answered. What prompted you to reply to it now?
Also, the code you posted is incorrect. A Date object doesn't have a value property.