Skip to main content
Known Participant
Sep 27, 2020 9:47 AM UTC
Answered

auto updating date fields

Hi, I want an auto date for two text fields. so every time i open this form, bellow two field dates should auto-update. can u pls help me to do this using javascript. thanks..

 

1. First payment date = Today date + two months
2. Second payment date = First payment date + 1 Year

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Sep 27, 2020 11:11 AM UTC

You can do it by placing the following code under Tools - JavaScript - Document JavaScripts (NOT inside a function):

 

var f1 = this.getField("Date1");
var f2 = this.getField("Date2");
var d1 = new Date();
d1.setMonth(d1.getMonth()+2);
f1.value = util.printd("mm/dd/yyyy", d1);
d1.setFullYear(d1.getFullYear()+1);
f2.value = util.printd("mm/dd/yyyy", d1);

Adjust the field names and date pattern as needed.

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Sep 27, 2020 11:11 AM UTC

You can do it by placing the following code under Tools - JavaScript - Document JavaScripts (NOT inside a function):

 

var f1 = this.getField("Date1");
var f2 = this.getField("Date2");
var d1 = new Date();
d1.setMonth(d1.getMonth()+2);
f1.value = util.printd("mm/dd/yyyy", d1);
d1.setFullYear(d1.getFullYear()+1);
f2.value = util.printd("mm/dd/yyyy", d1);

Adjust the field names and date pattern as needed.

Translate
omanbuxAuthor
Known Participant
Sep 30, 2020 1:03 AM UTC

Thank you very much. it's working perfectly.

Translate