Skip to main content
Participant
March 14, 2022
Answered

Reference error: document is not defined

  • March 14, 2022
  • 1 reply
  • 8991 views

Hi All

 

I'm a novice with javascript so would be very grateful for some help. I'm attempting to make new versions of some existing PDF forms so that they contain simple scripts to check things like fields not null and dates make sense, but I'm falling at the first hurdle in that I can't seem to refer to fields I've created within the pdf in javascript.

 

Whether I use this.getfield or document.getelementbyID I always get the error message "Reference error: document is not defined". I've tried searching the net for this error message in the context of PDFs but am drawing a total blank. I'd be very grateful if somebody can help please.

This topic has been closed for replies.
Correct answer try67

As I suspected it has transpired that I'm an idiot. The getField line was working fine, it was the document.print afterwards that was causing the error! So sorry for wasting your time.


Glad to hear it. In the future, if you have such issues and want help, you really need to post the full code, as well as the exact text of the error message you're getting, or share the actual file with us.

1 reply

try67
Community Expert
Community Expert
March 14, 2022

It's very important to know that Acrobat JS is:

1. Not the same as web-based JS,

2. Case sensitive.

 

So document.getelementbyID fails to work because of #1, and this.getfield fails because of #2.

The latter should work, but you have to use it correctly, which is: this.getField("FieldName")

Participant
March 14, 2022

Thank you so much for responding, that's really helpful.

 

Unfortunately I've checked the script and I am in fact using the correct case i.e. getField() but it's still throwing the error.

Participant
March 14, 2022

As I suspected it has transpired that I'm an idiot. The getField line was working fine, it was the document.print afterwards that was causing the error! So sorry for wasting your time.