9 Replies Latest reply on Jul 27, 2015 7:58 AM by Jaxsee

    Script for tick boxes, drop down boxes and form fields

    Jaxsee

      I rarely need to use javascript which is a good thing because I just cannot get my head round it, but you lovely people on here have helped me before so I'm hoping you could help again please.

       

      The image below is what I'm working with ..... The drop down box for Maximum Annual Volume contains 3 items (250,000, 1,000,000 and 2,000,000). After the volume has been chosen, one or more packs will be selected by ticking the box(es). Once they've been ticked I need the relevant Qtly Sub Fee and Onetime Fee to appear

      If someone could help with a script, I'd be very grateful. I'm using Acrobat Pro DC

      Thank you in advance

      Jackie

        • 1. Re: Script for tick boxes, drop down boxes and form fields
          try67 MVP & Adobe Community Professional

          Here's the custom calculation code for the first Quarterly Subscription Fee field. You'll need to copy and adjust it for each one of your other fields.

           

          event.value = "";
          var pk1 = this.getField("Pack1").valueAsString;
          if (pk1=="Yes") {
              var mav = this.getField("Maximum Annual Volume").valueAsString;
              if (mav=="250,000") event.value = 270;
              else if (mav=="1,000,000") event.value = 540;
              else if (mav=="2,000,000") event.value = 1080;
          }
          
          • 2. Re: Script for tick boxes, drop down boxes and form fields
            Jaxsee Level 1

            Thank you, but I'm obviously being very dumb as I can't get it to work!

            What have I missed??

             

            event.value = ""; 

            var Pk1 = this.getField("Pk1").valueAsString; 

            if (Pk1=="Yes")

                {var MaxAnnVol = this.getField("MaxAnnVol").valueAsString; 

                if (MaxAnnVol=="Up to 250,000") Pk1QtySubFee = 270; 

                else if (MaxAnnVol=="Up to 1,000,000") Pk1QtySubFee = 540; 

                else if (MaxAnnVol=="Up to 2,000,000") Pk1QtySubFee = 1080; 

            }

            • 3. Re: Script for tick boxes, drop down boxes and form fields
              try67 MVP & Adobe Community Professional

              What exactly is not working correctly? Are there error messages in the JS console?

              • 4. Re: Script for tick boxes, drop down boxes and form fields
                Jaxsee Level 1

                I'm getting nothing in the Qtly Sub fee box at all. I'm seeing this (which doesn't look good) in the Debugger console window

                 

                 

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                5:Document-Level:SetFieldValue

                SyntaxError: missing } after function body

                9:

                SyntaxError: missing } after function body

                9:

                SyntaxError: missing } after function body

                9:

                SyntaxError: missing } after function body

                9:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: illegal character

                6:

                SyntaxError: syntax error

                8:

                SyntaxError: syntax error

                9:

                SyntaxError: syntax error

                9:

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                TypeError: this.getField(...) is null

                2:Field:Calculate

                • 5. Re: Script for tick boxes, drop down boxes and form fields
                  try67 MVP & Adobe Community Professional

                  The "this.getField(...) is null" errors mean that you're trying to access a field-name which doesn't exist.

                  In the code you provided that doesn't seem to be the case, but it could come from another script in your file.

                  Keep in mind that JS is case-sensitive, so if a field is called "PK1" and you try to access "Pk1", it will fail.

                  • 6. Re: Script for tick boxes, drop down boxes and form fields
                    Jaxsee Level 1

                    I've renamed the fields and started from scratch. I'm not getting any errors now, but its still not working.

                     

                    Just to make sure its not me(!), where exactly should this code be put?

                    • 7. Re: Script for tick boxes, drop down boxes and form fields
                      try67 MVP & Adobe Community Professional

                      As the custom calculation script of "Pk1QtySubFee". If that's the case and it's still not working, could you share the file with us?

                      You can upload it to somewhere like Dropbox or Google Drive and post the link to it here, or you could even send it to me privately at try6767 at gmail.

                      • 8. Re: Script for tick boxes, drop down boxes and form fields
                        Jaxsee Level 1

                        It's in the right place.

                         

                        I've emailed the file to you

                        • 9. Re: Script for tick boxes, drop down boxes and form fields
                          Jaxsee Level 1

                          Thank you so much for your help - it's all working perfectly now.