Copy link to clipboard
Copied
Hello,
can you please help me? I have a form which I send to customers. The first field the will do is select the date they are working on the form... (I still have to figure out how to name the tab so the customer can see the tab name as date), anyways, what I need to happen next is to have my last tab on the bottom auto add 30 days from the date selected by the customer on top.
Example
Customer opens the PDF, and selects the date as 1 may 2018, base of that the form will automatically calculate and add the 30 days as 31 May 2018
This investigation must be completed no later than 31 May 2018. (The 31 May 2018 is auto completed and can not be changed, it will basically inform the customer that that is his/her due date).
Can you please help?
Thank you
HanzCzech
Copy link to clipboard
Copied
You placed the code in the wrong location. It needs to go under the Calculate tab, in the third option ("Custom calculation script").
Also, if your date format is actually "mm/dd/yyyy" (and not "dd/mm/yyyy", which is what I used) then you need to change that in the code, too.
Copy link to clipboard
Copied
Let's say the fields are called Date1 and Date2 and that the format is "dd/mm/yyyy".
Use this code as the custom calculation script of Date2:
var s1 = this.getField("Date1").valueAsString;
if (s1=="") event.value = "";
else {
var d1 = util.scand("dd/mm/yyyy", s1);
d1.setDate(d1.getDate()+30);
event.value = util.printd("dd/mm/yyyy", d1);
}
Copy link to clipboard
Copied
Hello,
thank you. I have just tried that, and it did not work... I am sorry, new with this.
Copy link to clipboard
Copied
You placed the code in the wrong location. It needs to go under the Calculate tab, in the third option ("Custom calculation script").
Also, if your date format is actually "mm/dd/yyyy" (and not "dd/mm/yyyy", which is what I used) then you need to change that in the code, too.
Copy link to clipboard
Copied
I appreciate you! Thank you very much!
Copy link to clipboard
Copied
Hello hanzCzech:
Did the code work for you?
I trird but di npot work for me.
Thanks for your help
Carlos
Copy link to clipboard
Copied
Hello,
I used your Your code also, and it was very useful for me, thank you for this.
I have a question, please see if you can have time to help me.
In your code there is an exact number which is 30. But I put a place in my form (name is "Days") where I can write the number which I need. Then I need to use this fillabele place ("Days") instead of 30 in your code.
Thank you in advance.
Copy link to clipboard
Copied
Sure. Just change this line of the code:
d1.setDate(d1.getDate()+30);
To this:
d1.setDate(d1.getDate()+Number(this.getField("Days").valueAsString));
Copy link to clipboard
Copied
Hello Try67,
How will i change the code if i want to add 5 years to Date1.
Sampe is 31/01/2000 on Date1 (dd/mm/yyyy format).
Date2 should have 31/01/2005
Copy link to clipboard
Copied
Use this:
d1.setFullYear(d1.getFullYear()+5);
Copy link to clipboard
Copied
I am trying to modify this code for +18 months. will you assist me with this?
Copy link to clipboard
Copied
I am trying to auto caluculate an expiration date for 5 years from the date entered by the end user in a text field named "Date", formated for date d/mm/yyyy. The field for the expiration date is named "Expiration Date" and formated for date in the same way. Could you possible provide the full script for this? Thank you
Copy link to clipboard
Copied
The script above does exactly that...
Copy link to clipboard
Copied
Hellotry67
Good day.
I tried but did not work for me, the value does not show.
Can you help me?
Thanks,
Carlos
Copy link to clipboard
Copied
Check the JS Console for error messages.
Copy link to clipboard
Copied
This is the most succint element of code to complete this task that I've seen after spending most of today searching. THANK YOU!
Copy link to clipboard
Copied
Hi,
Can anyone help as this does not seem to be working properly: Im using the code but ammended to show days:
var s1 = this.getField("Date1").valueAsString;
if (s1="") event.value = "";
else {
var d1 = util.scand("dddd dd/mm/yyyy", s1);
d1.setDate(d1.getDate()+1);
event.value = util.printd("dddd dd/mm/yyyy", d1);
}
This is not pulling from field Date1 though, it is using the current day as input. Can anyone see what ive done wrong?
Copy link to clipboard
Copied
Are you sure this is the actual value of the field, and not just a formatted value? What does it show when you click into it?