Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Javascript Date calculation
  FAQ FAQ  Forum Search   Register Register  Login Login

Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Javascript Date calculation

 Post Reply Post Reply
Author
Maureen View Drop Down
New Member
New Member


Joined: 09 Jun 2015
Location: Netherlands
Points: 24
Post Options Post Options   Quote Maureen Quote  Post ReplyReply Direct Link To This Post Topic: Javascript Date calculation
    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


Edited by Maureen - 13 Aug 2015 at 2:43pm
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 634
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post 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();
    d.setDate(1);
    d.setMonth(d.getMonth()+months);
    event.value = util.printd("mm/yyyy", d);
}
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
Maureen View Drop Down
New Member
New Member


Joined: 09 Jun 2015
Location: Netherlands
Points: 24
Post Options Post Options   Quote Maureen Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 634
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post 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 try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
Maureen View Drop Down
New Member
New Member


Joined: 09 Jun 2015
Location: Netherlands
Points: 24
Post Options Post Options   Quote Maureen Quote  Post ReplyReply Direct Link To This Post Posted: 14 Aug 2015 at 4:49pm
You're the best!! Thanks again. Wish I cloud do this
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

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

This page was generated in 0.063 seconds.