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

Javascript 1.6 stopped working, how to fix this?

Community Beginner ,
Jan 05, 2017 Jan 05, 2017

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?

TOPICS
Acrobat SDK and JavaScript , Windows
610
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
LEGEND ,
Jan 05, 2017 Jan 05, 2017

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.

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 Beginner ,
Jan 05, 2017 Jan 05, 2017

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.

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
LEGEND ,
Jan 05, 2017 Jan 05, 2017

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.

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
LEGEND ,
Jan 05, 2017 Jan 05, 2017

And if that checks out, add this line of code just before the one that generates the error:

app.alert(typeof Item);

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
LEGEND ,
Jan 05, 2017 Jan 05, 2017

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).

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 ,
Jan 06, 2017 Jan 06, 2017

The String object's indexOf method, yes, but not that of an Array...

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 Beginner ,
Jan 06, 2017 Jan 06, 2017

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!

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
LEGEND ,
Jan 06, 2017 Jan 06, 2017
LATEST

Is there any chance that whatever "Item" was set to changed?

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