Print Page | Close Window

Javascript Date calculation

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
Printed Date: 25 Feb 2020 at 12:17pm
Software Version: Web Wiz Forums 11.10 -

Topic: Javascript Date calculation
Posted By: Maureen
Subject: Javascript Date calculation
Date Posted: 13 Aug 2015 at 2:41pm

Hello all,

Can somebody help with this:

Field_A is a value for example 1000 (debt)
Field_B is a date (and date of the payment)
Flied_C is value for example 25 payment (per month)

I need a javascript for the following.
I want a calculation in Field_B that calculates the end date of the payment.
For example Field_A /Field_C =40 month, but the 40 months need to be converted to a date like month-year. By using the current date, the end date will be sept 2018 (this result I want in Field B).

Forgot this if Field_A or Field C is empty, then Field B shoud stay empty
Hope somebody can help

Posted By: try67
Date Posted: 14 Aug 2015 at 10:31am
You can use this code as the custom calculation script for Field_B:

var debt = +this.getField("Field_A").value;
var payment = +this.getField("Field_C").value;
if (debt==0 || payment==0) event.value = "";
else {
    var months = Math.ceil(debt/payment);
    var d = new Date();
    event.value = util.printd("mm/yyyy", d);

- Acrobat Expert - Contact me personally at
Check out my custom-made scripts website:

Posted By: Maureen
Date Posted: 14 Aug 2015 at 3:38pm
Thank you so much, it works!. Somebody sitting with me checking the form. Now he aks if its possible to expand the script with field_D. In this fieled the balance of the debt is filled in. (It's a form for people with financiel problems and need a free food package) It happens that sometime people don't know the total debt, but they know the balance of the debt. Example they know that the balance is 1000, but they don't remember what the total debt was, so they only fill in 1000. The script from you works excellent if the total debt (Field_A) is filled in. Is it possible to "expand" the script in a way that if Field_A is empty, then the value of Field_D it should be used to execute the script. If both fields (A and D) are filled in, then the value of Field D should be used. We know we asked a lot, but we want to help these people to get some food.

Posted By: try67
Date Posted: 14 Aug 2015 at 3:41pm
Replace the first line of the code with this:

var debt = +this.getField("Field_D").value;
if (debt==0) debt = +this.getField("Field_A").value;

- Acrobat Expert - Contact me personally at
Check out my custom-made scripts website:

Posted By: Maureen
Date Posted: 14 Aug 2015 at 4:49pm
You're the best!! Thanks again. Wish I cloud do this

Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 -
Copyright ©2001-2017 Web Wiz Ltd. -