5 Replies Latest reply on Feb 7, 2017 12:14 PM by jasperwt

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

    jasperwt

      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

        • 1. Re: Getting Error 'indexOf is not a function' - Acrobat X
          Bernd Alheit Adobe Community Professional & MVP

          You must use the value of the field. Example:

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

          1 person found this helpful
          • 2. Re: Getting Error 'indexOf is not a function' - Acrobat X
            Karl Heinz Kremer Adobe Community Professional

            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,");
            
            1 person found this helpful
            • 3. Re: Getting Error 'indexOf is not a function' - Acrobat X
              jasperwt Level 1

              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

              • 4. Re: Getting Error 'indexOf is not a function' - Acrobat X
                Bernd Alheit Adobe Community Professional & MVP

                Use:

                if (n >= 1)

                 

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

                1 person found this helpful
                • 5. Re: Getting Error 'indexOf is not a function' - Acrobat X
                  jasperwt Level 1

                  You are absolutely correct!

                  Thanks for your help.

                  Works great.