These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Help with auto-filling dates on forms

kapoli
Registered: May 6 2011
Posts: 6

Can someone help me figure out how to auto-fill the dates on a form so that someone would only need to enter in one date, and have the rest automatically generate based on that information?
 
Like if I put in Monday's date, and I wanted to have Tuesday's, Wednesday's, Thursday's, and Friday's dates automatically fill themselves in, how would I do that in Acrobat 9?
  
Thanks in advance for any help.

My Product Information:
Acrobat Pro 10.0.2, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Place the function as a doc-level script.
Now, to calculate the next day after Date1, use this code as the custom calculation:
showFutureDate(1);
Change the value of the parameter to change the number of days in the future to show.



function showFutureDate(numDays) {
d1 = getField("Date1").value;
if (d1=="") {
event.value = "";
} else {
var d2 = util.scand("mm/dd/yyyy", d1);
d2.setTime(d2.getTime()+(numDays*86400000));
event.value = util.printd("mm/dd/yyyy", d2);
}
}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

kapoli
Registered: May 6 2011
Posts: 6
Thank you for your reply. I'm sorry, but I'm still having a little bit of trouble. I'm very new to Acrobat... just want to make sure I have this right...


I have five fields on this form right now:

"Monday"
"Tuesday"
"Wednesday"
"Thursday"
"Friday"

(Obviously I can/will change those to be named anything they need to be)

I'm trying to make it so that our employees open the form and just fill out Monday's date (M/D/YY or whatever format it needs to be) and then Tuesday - Friday just fill themselves in. So if I type 5/1/11 in for Monday, the other dates (5/2/11, 5/3/11, 5/4/11, and 5/5/11) would be automatically calculated. I do not want Monday's date to be automatically calculated, though.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
So you need a field into which the user enters a date, and then a script checks to see if the date' days of the is a "Monday" and if it is, then fill in a series of day fields with the following dates.

It is possible to get the day of a week from a date by scripting and converting the date string into another format and then extracting the day of the week from that item. The exact code will depend upon whether you are using Acrobat or LiveCycle Designer and if LiveCycle Designer the scripting language that use.

In Acrobat or LiveCycle Designer you can convert the date string to the JavaScript date object and the 'getDay()' method to obtain the day of the week.

In LiveCycle Designer FormCalc, you can convert the date string to the number of days and then convert that number of days back to a string value that is the day of the week.

Once you have in inputted valid date, you can use that date and JavaScript's or FormCalc's arithmetic operators and formatting functions to populate the other fields.

George Kaiser

kapoli
Registered: May 6 2011
Posts: 6
Hi George,

I don't think that I need to check and verify that the date entered is a date for a Monday. Just have the first field be a manually entered date (5/1/11 or something like that) and then have the next four consecutive dates calcuated and auto-filled.

So if someone types in 5/1/11, then the other fields will calculate and display automatically as 5/2/11, 5/3/11, 5/4/11, 5/5/11.

I don't know how to convert the manually entered date to a date string and add days to the date from there.

Field #1 = "manually entered date" (I think you're saying this is what needs to be converted to a date string?)
Field #2 = "manually entered date" + 1
Field #3 = "manually entered date" + 2
Field #4 = "manually entered date" + 3
Field #5 = "manually entered date" + 4

I need to figure out the Javascript to make the above result happen.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Users enter a date string, the numbers for the month, day, and year and the special text separator characters. This is the formatted displayed value. You can only concatenate this text sting. If you need to perform any arithmetic or format conversion, you need to use special functions or methods to convert this text string to an object or special value used for processing dates.

Have a look at Thom Parker's JavaScript tutorial Working with date and time in Acrobat JavaScript (part 2 of 3) and the MDC JavaScirpt Reference 1.5.A sample Sample Time Sheet contains the code and additional code for computing time worked daily and weekly.

George Kaiser

scotl578
Registered: Jun 6 2011
Posts: 5
how do i have the other fields blanks before a date is entered into any of the field?
scotl578
Registered: Jun 6 2011
Posts: 5
can i have a user enter a date in any field and the other fields would auto populate?