Copy link to clipboard
Copied
I have a pdf that when it is opened I want dates to be auto-populated for printing purposes. I've researched and can only make it partially work. The only success I've had is by editing my pdf and creating my text fields and formatting them for my date format (mm-dd-yy). Then to go to my page layout and open page properties, click on actions, and add an action that triggers on Page Open to run a javascript command. The only command I'm getting to work is the following:
var f = this.getField("Sunday");
f.value = util.printd("mm-dd-yy", new Date());
This correctly and automatically populates my date field but only for the day I do it. I'm trying to make the dates work for future dates also, such as tomorrow. It appears the main javascript function is to use a getDate() command and do +1 for tomorrow but I can not get it to do this. I've searched for different variations of adding tomorrow to the form and none of them appear to work or at least won't populate their fields upon opening my document. IF anyone can offer any help I'd appreciate it.
Copy link to clipboard
Copied
To populate date on opening you can use document level javascript (while in prepare form tool click on 'More' and select 'Document JavaScript' or press SHIFT+D ) and use something like this:
var days = util.scand("mm-dd-yy", new Date())
days.setDate(days.getDate() +1);
this.getField("Day").value = util.printd("mm-dd-yy", days);
Just change field name to your actual field name.
Copy link to clipboard
Copied
Is there a way upon opening that the 1st date not to change? I need Monday's date to stay the same when form is reopened, but Tue-Sun to change +1.
Copy link to clipboard
Copied
To populate date on opening you can use document level javascript (while in prepare form tool click on 'More' and select 'Document JavaScript' or press SHIFT+D ) and use something like this:
var days = util.scand("mm-dd-yy", new Date())
days.setDate(days.getDate() +1);
this.getField("Day").value = util.printd("mm-dd-yy", days);
Just change field name to your actual field name.
Copy link to clipboard
Copied
There's no need to use scand to create a new Date object for the current day. You can just use it directly.
Copy link to clipboard
Copied
Is there a way upon opening that the 1st date not to change? I need Monday's date to stay the same when form is reopened, but Tue-Sun to change +1.
Copy link to clipboard
Copied
You can add this:
if(this.getField("Day").value == ""){
//put script here
}
Copy link to clipboard
Copied
Updated and I'll have to wait til tomorrow. Thanks for your quick reply!
Copy link to clipboard
Copied
It worked!!!!