Copy link to clipboard
Copied
I have a time sheet that I have turned into a form and I would like to make the start date of the week auto populate the rest of the dates. Is there a way to do this? Thanks for the help.
Copy link to clipboard
Copied
Yes, you can, with a script. This question comes around quite often and I know that solutions have been provided. Here are the results of a quick search on these forums:
https://forums.adobe.com/search.jspa?q=auto%20dates
Copy link to clipboard
Copied
Thanks for the info. It looks like all of these change the date every time you open it. I need to input the date in a field and then have it populate the rest of the dates from there. Also if i do get this to work will it work on an IOS Device?
Copy link to clipboard
Copied
Before you decide on which script to use, verify that any code conforms to what is supported on iOS. You can find that documentation here...
JavaScript for Acrobat Reader Mobile API Reference (iOS)
For example, several of the scripts referenced in that list use the field property "valueAsString" which is no supported on Adobe Reader for iOS.
Copy link to clipboard
Copied
In the search link I posted above there were several different threads with different solutions. The important bit is find code that calculates consecutive dates the way you want them. That code can be applied to a form in many different ways.
For you the easiest, and most workable solution (across platforms) is to have a single calculation script that finds all the dates and populates the other date fields. A good choice is the first field
Here's some example code, it assumes the first date in the table is named StartDate, an the following date fields are named "Date1" thru "Date6".
var startDate = this.getField("StartDate").value;
if (dtStart!="")
{
var dtWkDay = util.scand("mm/dd/yyyy", dtStart);
for(var i=1;i<7;i++)
{
this.getFiel("Date"+i).value = util.printd("mm/dd/yyyy",dtWkDay.setDate(dtWkDay.getDate()+1);)
}
}
However, as Joel has pointed out, you have a problem with Mobil PDF viewers because none of them provide anything close to the complete Acrobat JS model. You should test on both the Acrobat mobile Reader and PDF Expert from Readdle, which is the best IOS PDF viewer
Copy link to clipboard
Copied
Thom,
Thank you for all the help I have tried to put the code you supplied in but i keep getting this error:
any help is greatly appreciated.
Copy link to clipboard
Copied
Replace line #7 of the code above with this:
this.getField("Date"+i).value = util.printd("mm/dd/yyyy",dtWkDay.setDate(dtWkDay.getDate()+1));