Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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")
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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")
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Will do, thanks again
Copy link to clipboard
Copied
I too am having similar issues, but in a slightly different context, below you can find both the code referenced as well as the adobe doc reference used. In short, its a similar issue of not understanding the getField() method fully. the documentation linked has implied that doc is like a global this, but either or doesnt seem to work. it may be that this documentation is dated, ive heard that adobe has been hands off of java for well over a decade, but with that it is troublesome at the least to get definitive information on the topic. Any assistance in the matter as well as references to any more up to date documentaion would be infinitley helpful to both myself and my team.
/*********** belongs to: AcroForm:Send It!:Annot1:MouseUp:Action1 ***********/
var Addressplus = "mailto:<address-ommited>?cc="
// add the value of ITButton to the new variable ITAddr
var ITAddr = this.getField("ITButton");
// if ITAddr is checked, add IT address to the email
if (ITAddr.value == "Yes") { Addressplus += ";" + "<address-ommited>" };
// add the value of PubsButton to the new variable PubsAddr
var PubsAddr = this.getField("PubsButton");
// if PubsAddr is checked, add Pubs address to the email
if (PubsAddr.value == "Yes") { Addressplus += ";" + "<address-ommited>" };
var message = doc.getField(EmailDialogue).value; // ERR... unsure as to why
if (message.value == "") { message = "Please see attached form, thank you" }; // default message if in event dialogue box is empty
ButtonActive(Addressplus);
//</ACRO_script>
//</AcroForm>
reference from https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html
function logAlerts( doc ) { count = 0; doc.alerter = { dispatch( alert ) { doc.getField("AlertLog").value += "Alert #" + ++count + ": " + alert.type + "n"; } } }
Thank you for your time
Copy link to clipboard
Copied
In the context of the first code you didn't define a variable called "doc", so you can't use it.
It's not the same as "this", which is a global object (that can refer to different things, by the way. It doesn't always have to point to the current Doc object). Also, field names must be in quotes. So change this line:
var message = doc.getField(EmailDialogue).value; // ERR... unsure as to why
To:
var message = this.getField("EmailDialogue").value;
Copy link to clipboard
Copied
Appologies, i should have been clearer for this. doc.getField(); was as a replacment to this.getField(); while true it does run as if doc is undefined, from the link referenced it treats doc as a self reference to global, like this. appologies for the confusion on that section.
with that, is there any reason why a text field inside a this.getField("<EmailDialogue>").value; would not function even while <EmailDialogue> is verbatim to the fields name? the error received implys that the text field doesnt exist.
ReferenceError: TESTBOX is not defined // appologies, replying to this first thing in the morning and havent had the chance to change TESTBOX back to EmailDialouge, was playing with different field names incase there was a syntax error on that grounds.
Copy link to clipboard
Copied
This is not what that error means. It means you're trying to access a variable that doesn't exist (TESTBOX), not a field. When you try to access a non-existing field the error you get is something like "TypeError: this.getField(...) is null".
But there's no TESTBOX anywhere in the code you shared, so it's very hard to help you debug code we can't see.
Copy link to clipboard
Copied
that doesnt awnser the question, youve just re explained that variables need to be initialized. if its not a variable but a field from the document then how does one access it. "is there any reason why a text field inside a this.getField("<EmailDialogue>").value; would not function even while <EmailDialogue> is verbatim to the fields name?" outlined that i understood this wasnt a variable. no where else has a variable needed to be established for me to check a fields value, only for setting its value to a variable.
in summary
is there any reason why a text field inside a this.getField("<EmailDialogue>").value; would not function even while <EmailDialogue> is verbatim to the fields name?
with that, ive already posted the relevent code above. there isnt more other than the function for sending the email, one that this script cannot reach at this point due to the previously mentioned issue.
Copy link to clipboard
Copied
Where in the script does you use:
this.getField("<EmailDialogue>").value;
?
Copy link to clipboard
Copied
I had said i had used a few itterations of the function, swapping this for doc as done in documentation, but for reference this line
var message = doc.getField(EmailDialogue).value; // ERR... unsure as to why
has been re written and tested as
var message = this.getField(EmailDialogue).value;
var message = this.getField(TESTBOX).value; // renamed EmailDialogue -> TESTBOX for testing, mabye name caused issues?
var message = this.getField(EmailDialogue);
and
var message = this.getField(TESTBOX);
at this point i beleive the issue to be a lack of understanding of some syntaxual requirment or using the wrong method to access information from the form itself.
Copy link to clipboard
Copied
When the name of the field is EmailDialogue use this.getField("EmailDialogue").value;
Copy link to clipboard
Copied
that throws this error
ReferenceError: EmailDialogue is not defined
and before i am told that is because i am not defining EmailDialogue and i chase my own tail again. im going to stop now. here is all the information i can provide, i loathe the idea of giving adobe or any related service my time, and if i never see the name adobe again ittle be too soon. make what you will of this, im telling my team that were finding something else. the js is a txt for uploading purposes.
Copy link to clipboard
Copied
Good luck, bye.
Copy link to clipboard
Copied
You keep missing the point, so I will try to make it as clear as possible, one last time.
You're continuously confusing three different things:
1. this.getField(EmailDialogue).value;
2. this.getField("EmailDialogue").value;
3. this.getField("<EmailDialogue>").value;
Line #1 accesses (or attempts to access) a field whose name is defined by a variable called EmailDialogue, since there are no quotes around the name.
So, it has to be preceded by something like this:
var EmailDialogue = "Text1";
In that case, line #1 will access a field called "Text1". The name of the variable is not important.
Line #2 accesses (or attempts to access) a field whose name is exactly "EmailDialogue" (excluding the quotes, of course, which are used to identify the boundaries of a string in JS).
Line #3 accesses (or attempts to access) a field whose name is exactly "<EmailDialogue>" (excluding the quotes, but INCLUDING the bigger-than/smaller-than symbols).
Edited: I had to post this reply by email and it screwed up some things... Fixed it now.

