Copy link to clipboard
Copied
I have a Date Field and I'm trying to preload it with the current date; however, it's not working. This is the script I have:
var f = this.getField("Date4");
f.value = util.printd("m/d/yyyy", new Date());
Date4 is the name of the Date Field.
I don't see the current load when in Preview mode.
Copy link to clipboard
Copied
For validate script you need to change field value for the script to trigger, so either use under calculate tab or as one of the action (Mouse UP) it all depends on how you wish to trigger script and if you wish script to update date or remain fixed.
Also, you can shorten script like this: event.value = util.printd("m/d/yyyy", new Date());
If you use as action script, change event.value to event.target.value
Copy link to clipboard
Copied
Thank you so much for the help. I want to automatically show the current date when the PDF is open but yet allows the user to pick a different date if he/she wants to. I put the script on the page properties as shown below it's still not showing the current date when the form is opened in Acrobat.
Copy link to clipboard
Copied
Move your code to a doc-level script, via Tools - JavaScript - Document JavaScripts. Create a new item there called "scripts", delete the function that is created by default and paste your code, and you're done.
However, be advised this will overwrite any input the user entered into the field the next time they open the file.
If you don't want to do that then add this before the first second line:
if (f.valueAsString=="")
But then it would not update the field, even if the user didn't enter anything into it... Basically it will only update it if the field was empty when the file was opened.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now