Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Autopopulating Date Field

New Here ,
Feb 21, 2025 Feb 21, 2025

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?

TOPICS
JavaScript , PDF forms
322
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 21, 2025 Feb 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;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2025 Feb 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;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2025 Feb 21, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2025 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2025 Feb 21, 2025
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines