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

Getting Error 'indexOf is not a function' - Acrobat X

Community Beginner ,
Feb 07, 2017 Feb 07, 2017

Hello,

I have a document level javascript that is looking for character strings to determine a result.

Why would it throw this error?


function webaddress() {
          var one = this.getField("CompanyName");
          var two = this.getField("WebAddress");
          var three = this.getField("dealerCSZ");
          var n = three.indexOf("MN,");
          var n1 = three.indexOf("IN,");
          var n2 = three.indexOf("OH,");

        // evaluate address for proper name

         if (n.value>=1)
              {
             one.value='TRUCK COUNTRY USED TRUCK CENTER';   
             two.value='www.truckcountry.com'; 
              }
         else if (n1.value>0 || n2.value>0)
              {
             one.value='STOOPS FREIGHTLINER - QUALITY TRUCKS';   
             two.value='www.stoops.com'; 
              }
         else  
              {
             one.value='TRUCK COUNTRY';   
             two.value='www.truckcountry.com'; 
              }

}
webaddress(); // call my function

TOPICS
Acrobat SDK and JavaScript , Windows
993
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

correct answers 1 Correct answer

Community Expert , Feb 07, 2017 Feb 07, 2017

Use:

if (n >= 1)

Info: the variables n, n1, and n2 are local variables of the function.

Translate
Community Expert ,
Feb 07, 2017 Feb 07, 2017

You must use the value of the field. Example:

var n = three.value.indexOf("MN,");

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 07, 2017 Feb 07, 2017

Actually, you should use the valueAsString property instead of value - otherwise the code will throw an exception if the value is not already a string:

var n = three.valueAsString.indexOf("MN,");

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 ,
Feb 07, 2017 Feb 07, 2017

All - thanks for the quick reply.

I added 'valueAsString' and am no longer getting an error.

However, the variables n, n1, and n2 are all showing 'undefined' when I print them out.

Is the indexOf method able to evaluate a comma?

Here is the current script.

function webaddress() {
          var one = this.getField("CompanyName");
          var two = this.getField("WebAddress");
          var three = this.getField("dealerCSZ");
          var n = three.valueAsString.indexOf("MN,");
          var n1 = three.valueAsString.indexOf("IN,");
          var n2 = three.valueAsString.indexOf("OH,");

        // evaluate address for proper name

         if (n.value>=1)
              {
             one.value='TRUCK COUNTRY USED TRUCK CENTER';   
             two.value='www.truckcountry.com'; 
              }
         else if (n1.value>0 || n2.value>0)
              {
             one.value='STOOPS FREIGHTLINER - QUALITY TRUCKS';               two.value='www.stoops.com'; 
              }
         else  
              {
             one.value='TRUCK COUNTRY';   
             two.value='www.truckcountry.com';
              }

}
webaddress(); // call my function

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 07, 2017 Feb 07, 2017

Use:

if (n >= 1)

Info: the variables n, n1, and n2 are local variables of the function.

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 ,
Feb 07, 2017 Feb 07, 2017
LATEST

You are absolutely correct!

Thanks for your help.

Works great.

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