Skip to main content
Known Participant
February 21, 2025
Answered

Autopopulating Date Field

  • February 21, 2025
  • 2 replies
  • 834 views

Hi,

 

Esteemed users of Acrobat Forms. I am looking for some help!

I am using the following  Javascript to auto populate Date field. Intent is that a user when first time opens the form, this date field will be auto populated and will stay same.

 

var currentTime = new Date();

var month – currentTime.getMonth() + 1;

var day = currentTime.getDate();

var year = currentTime.getFullYear();

var rTime = day + “/” + month + “/” + year;

this.getField(“DateReceived”).value = rTime;

 

I tried all the following three options for entering Javascript (one at a time) and in all cases I am getting the same error message: “Error: SyntaxError: Illegal character at line 3.”

  1. Action > Mouse Up > Run Java Script
  2. Action: Mouse Up > Execute Menu |  Validate > Run Custom Validation Script
  3. Action: Mouse Up > Execute Menu | Calculate > Custom Calculation Script

 

Since I am not a Java programmer, I was wondering if somebody could please help resolve this?

Correct answer Bernd Alheit

Try this:

var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var rTime = day + "/" + month + "/" + year;
this.getField("DateReceived").value = rTime;

2 replies

try67
Community Expert
Community Expert
February 21, 2025

The error message is caused by the curly quotes you're using. You must only use straight quotes (single or double) in your code for strings.

anil_BAuthor
Known Participant
February 21, 2025

Thanks a lot for pointing out this. I will note it for future reference. 

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
February 21, 2025

Try this:

var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var rTime = day + "/" + month + "/" + year;
this.getField("DateReceived").value = rTime;
anil_BAuthor
Known Participant
February 21, 2025

Thanks a lot. That works!  [Just found out waht I was ding wrong.]