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

Date calculated based on user date input

anneashley
Registered: Apr 22 2008
Posts: 4

I am using Acrobat 8.0 Pro and LiveCycle. Creating a timesheet and want users to only fill in the "week ending" date field, then have the rest of the date fields calculate based on that entry. Not great at JavaScript.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Are you using AcroFroms (Acrobat) or LiveCycle Designer.

Here is an example using Acrobat. The field with the ending date of the week is "week.ending", the days of the week are named "date.0" - "date.6", "date.6" being the same date as the "week.ending". The format for the "week.ending" field is "mmmm dd, yyyy" and the format for the "date" fields is "none" since the sript will format the text to "mm/dd".

The "custom calculation script" for the "week.ending" field is:

 // process if week.end field is not emptyif (event.value != "") {// get date time object for the "week.ending" fieldvar oWeekEnd =  util.scand("mmmm dd, yyyyy", this.getField("week.ending").value);// get array of "date" fieldsvar aDate = this.getField("date").getArray();// loop through each field of the "aDate" field array and fill in each date base on element member numberfor (i = 0; i < aDate.length; i++) {aDate[i].value = util.printd("mm/dd", new Date( oWeekEnd.getYear(), oWeekEnd.getMonth(), oWeekEnd.getDate() - (aDate.length - 1 - i) ) );} // end for } else {this.resetForm(aDate);}

George Kaiser

anneashley
Registered: Apr 22 2008
Posts: 4
I am designing in LiveCycle. Do I place this script in the script editor? I am a remedial JavaScript.