Copy link to clipboard
Copied
Maybe someone here can help -
I am trying to create a schedule of dates that would start on a date that I enter and then every subsequent date would be exactly the same day the following month for 36 consecutive months.
For example if the first date is 8/17/2023, then it would automatically fill the rest at 9/17/2023, 10/17/2023 etc for a total of 36 months.
Can someone please explain how i can do this?
Much Appreciated!
Copy link to clipboard
Copied
OK. In that case, assuming the fields are named NextMonth1-NextMonth36, you can use this code as the custom Validation script of the original date field:
if (event.value) {
var d = util.scand("mm/dd/yyyy", event.value);
if (d.getDate()<=28) {
// data is before (or equal to) the 28th -> populate the other fields
for (var i=1; i<=36; i++) {
d.setMonth(d.getMonth()+1);
this.getField("NextMonth"+i).value = util.printd("mm/dd/yyyy", d);
}
} else {
// date is after the 28th -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("NextMonth"+i).value = "";
}
}
} else {
// field is empty -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("NextMonth"+i).value = "";
}
}
Copy link to clipboard
Copied
This is the Using the Community forum (which is the forum for issues using the forums).
Please tell us what Adobe application you are using so that this can be moved to the proper forum for help.
Copy link to clipboard
Copied
sorry - using Acrobat Pro DC
Copy link to clipboard
Copied
What if entered date is 31st and next month has 30 days what should be date in that case day before or day after?
Copy link to clipboard
Copied
Nesa,
I don't want it like that if you see the example, it has to be the same day on each month - so if the 1st date is 8/17/2023, then the next date is 9/17/23 and so on - Thanks
Copy link to clipboard
Copied
That works for day 17, but not 31, as Nesa correctly pointed out, and in some cases not even for 30 or 29... What if the first day is 31/01/2023? There's no 31/02/2023... Or 31/04/2023, or 31/06/2023, etc.
Copy link to clipboard
Copied
yes, i get that - but if i wanted to do it for all dates before the 28th, I could create a separate template to manually input if the first date is the 29th, 30th, or 31st. It would still make things easier if i had 2 schedules where at least one of them I could have the dates input as i stated and then the other manual as I am currently doing. Can you show me a way to do what I am looking for up to the 28th?
Copy link to clipboard
Copied
OK. In that case, assuming the fields are named NextMonth1-NextMonth36, you can use this code as the custom Validation script of the original date field:
if (event.value) {
var d = util.scand("mm/dd/yyyy", event.value);
if (d.getDate()<=28) {
// data is before (or equal to) the 28th -> populate the other fields
for (var i=1; i<=36; i++) {
d.setMonth(d.getMonth()+1);
this.getField("NextMonth"+i).value = util.printd("mm/dd/yyyy", d);
}
} else {
// date is after the 28th -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("NextMonth"+i).value = "";
}
}
} else {
// field is empty -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("NextMonth"+i).value = "";
}
}
Copy link to clipboard
Copied
when i enter the javascript under actions is it "on blur"? (other choices are on focus, mouse up down etc)
Copy link to clipboard
Copied
nevermind that one but i entered the code after viewing thumbnail and page properties, run javascript - but it won't do the other dates after i tested it. Obiously i am inputting it wrong somewhere can you walk me through it? I appreciate it.
Copy link to clipboard
Copied
try67 has posted it:
"you can use this code as the custom Validation script of the original date field"
Copy link to clipboard
Copied
I did that but the other dates are not changing?
Copy link to clipboard
Copied
Please share the file for further help.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You did not apply the code where I indicated. Also, there are errors in the JS Console when you open the file (since the code is under the Page Open action...).
The fields are not named "NextMonthX", but "Payment DateX". Also notice there are only 35 fields, starting from 2. Adjust the code accordingly.
In addition, fields 31 to 36 contain "Row" in the middle of their names, unlike the other fields. They should be renamed.
Copy link to clipboard
Copied
ill fix the code but what do you mean i didn't put code where you indicated? i thought i added the javascript to the start date?? if i didnt then can you walk me through the steps to add it there?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Change:
i=1 to i=2 since your fields start from number 2 not 1.
Copy link to clipboard
Copied
Select 'Prepare form' tool, then right click on start date field and select 'properties' then select 'Validate' tab and put script there.
Copy link to clipboard
Copied
got it but it is still skipping a month in the beginning?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
this is the code i entered under validate on the start date - for me it is still skipping a month not sure why:
if (event.value) {
var d = util.scand("m/d/yyyy", event.value);
if (d.getDate()<=28) {
// data is before (or equal to) the 28th -> populate the other fields
for (var i=1; i<=36; i++) {
d.setMonth(d.getMonth()+1);
this.getField("PAYMENT DATE"+i).value = util.printd("m/d/yyyy", d);
}
} else {
// date is after the 28th -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("PAYMENT DATE"+i).value = "";
}
}
} else {
// field is empty -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("PAYMENT DATE"+i).value = "";
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Read my post above.
Copy link to clipboard
Copied
Got it! i missed your post Nesa where you said to change i to =2. Thank you both so much - this will make it much easier for me. I really appreciate both you and your patience with me. Thanks again