Copy link to clipboard
Copied
is it possible to auto populate a PDF with the last 2 digits 20__ - 20__ with current year to next year every time I open up a PDF page? example 2017-2018?
1 Correct answer
You need to add another field and then increment the year value by 1.
A possible script is:
var f = this.getField("Today");
f.value = util.printd("yy", new Date());
f = this.getField("NextYear");
f.value = Number(util.printd("yy", new Date())) + 1;
For this to work one needs to be careful about the type of variables, that is , there is a significant difference between a String variable and a Number variable and how the "+" operator works.
Copy link to clipboard
Copied
You can use this code to populate the whole thing into a field:
var now = new Date();
this.getField("Years").value = "" + now.getFullYear() "-" + (now.getFullYear()+1);
Copy link to clipboard
Copied
I get a syntaxError: missing ; before statement 2: at line 3 when I put this in the JavaScript Editor. How do I correct that? Thanks for your help.
Copy link to clipboard
Copied
What exact code did you use?
Copy link to clipboard
Copied
I copied & pasted your code exactly into my Acrobat Javascript editor but it returned with that syntaxError:
"missing ; before statement 2: at line 3"
so the code didn't work.
Copy link to clipboard
Copied
There was a missing "+" in the second line of the code.
var now = new Date();
this.getField("Years").value = "" + now.getFullYear() + "-" + (now.getFullYear()+1);
Another document level script could be:
var now = new Date();
this.getField("Years").value = (now.getFullYear()).concat("-", (now.getFullYear() +1));
You may need to change the field name to match your form.
Copy link to clipboard
Copied
That didn't work...
I have this JavaScript on Page Properties:
var f = this.getField("Today");
f.value = util.printd("yy", new Date());
so when the page pull up "20__ to 20__" comes up auto populated as "2017 to 20__".
Any way to add another script onto the above so it will show 2017 to 2018?
Copy link to clipboard
Copied
You need to add another field and then increment the year value by 1.
A possible script is:
var f = this.getField("Today");
f.value = util.printd("yy", new Date());
f = this.getField("NextYear");
f.value = Number(util.printd("yy", new Date())) + 1;
For this to work one needs to be careful about the type of variables, that is , there is a significant difference between a String variable and a Number variable and how the "+" operator works.
Copy link to clipboard
Copied
That totally worked! Thank you gkaiseril and try67 for your help!

