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

Custom Calculation Script - Adding Months to a Date from a list box

alwclimbs
Registered: Jan 6 2011
Posts: 1

I am creating a prepaid membership form where I want users when selling these memberships to have little access to change anything manuallly. I have designed it so that there are two list boxes which determine what kind of membership the customer is purchasing and the duration of the membership (3 months, 6 months, 1 year).
 
Now I have the prices calculating perfectly. However, now I have two text fields, one that has the membership beginning date and the membership end date.
 
The Membership Begin date automatically calculates today's date. I want to be able to have the Membership Ends field correctly give the membership ending date based on what Duration is chosen.
 
Ex. 1/05/11 + 3 Months = 4/05/11
 
Problem: The membership for One Year is value set for 11 because of a discount. I need to add one month to make the date correct.
 
I've tried alot of codes and I'm realizing I'm too inexperienced to get anywhere! Thank you for the help!
 
List Box name - "Duration" and all it has are export values
 
The coding for the Begin date is event.value = util.printd("mm/dd/yyyy", new Date());
 

My Product Information:
Acrobat Pro Extended 9.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you are having problems with the date calculation you'll find what you need in this 3 part article:Dates and TimesFor performing a conditional calculations, see this article:Conditional Calculations

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can use the 'getMonth()' and 'setMonth()' method to adjust the number of months.

/// get the current date object
var oNow = new Date();
// get number of duration months
var nAddMonths = this.getField('Duration').value;
// if duration is 11 months add the bonus month
if (nAddMonths == 11) ++nAddMonths;
// increment and set the new month value (current month plus duration)
oNow.setMonth( oNow.getMonth() + nAddMonths );
// set the event value with the display format
event.value = util.printd("dd mmm yyyy", oNowd);

George Kaiser