Copy link to clipboard
Copied
I have a PDF form with embedded Javascript that I made a while back. It's been working fine for months, but today it started giving me this error:
TypeError: Item.indexOf is not a function
I looked around the forum and found that this seems to be a problem with older Acrobat not supporting JS 1.6. But I'm using Acrobat 2015, which should support this call. And again, this script had been working fine until today.
I don't know if it's related, but the only factor I can think of is that I've downloaded and used a heavily JSed PDF. That PDF worked just fine, but would it be possible that this PDF somehow disabled my Acrobat's JS 1.6 support?
How do I get JS 1.6 support back?
Copy link to clipboard
Copied
What it "Item", exactly? This problem probably isn't related to what you're assuming. If you're using it with something that's supposed to be a string, I'd guess that it's not actually a string in this case. Same idea if it's supposed to be an array, but isn't.
A fairly common example of how this could happen is when you get the value of a text field using the value property. Most of the time it will be a string, but it could also be a number or a boolean. Since a number of boolean doesn't have an indexOf method, you'll get this error. The fix in cases like this is to get the field value as a string using the valueAsString field property.
Copy link to clipboard
Copied
Thanks for the answer, but there doesn't seem to be any problem with the script itself. I tested the exact same PDF on a different machine and it runs just fine. Also runs fine in Adobe Reader on the same machine.
And yes Item is indeed a string.
Copy link to clipboard
Copied
What happens when you open the interactive JavaScript console by pressing Ctrl + J and enter this line of code:
"ABCD".indexOf("B");
and execute it by pressing Ctrl + Enter
It should return 1.
Copy link to clipboard
Copied
And if that checks out, add this line of code just before the one that generates the error:
app.alert(typeof Item);
Copy link to clipboard
Copied
By the way, the indexOf string method has been there from the beginning (JavaScript 1.0 in 1995), so i'ts been available since JavaScript was introduced to Acrobat 3.5 (JavaScript 1.2).
Copy link to clipboard
Copied
The String object's indexOf method, yes, but not that of an Array...
Copy link to clipboard
Copied
Hmm. Weird. The error just went away as mysteriously as it appeared. Didn't even reboot, reinstall or any of the standard magical fixes.
Thanks for all the help -- hope it doesn't come back again!
Copy link to clipboard
Copied
Is there any chance that whatever "Item" was set to changed?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now