8 Replies Latest reply on Aug 6, 2014 6:34 PM by Fredy119

    Validating an optionsgroup

    Fredy119

      Hi

      I want to call a function via a button to validate  optiongroups

      groupnames: option1 option2 ............

      field selection names: auswahl1, auswahl2, .......

      I used the following code:

       

      function opionsfelder()

      {

      var f = this.getField("option1 auswahl1");

      if(f.isBoxChecked(0))

      {f.fillColor = color.red;

      }

       

      var f = this.getField("option1 auswahl2");

      if(f.isBoxChecked(0))

      {f.fillColor = color.green;

      }

      }

      It doesn't work probably because the field reference is wrong.

      Can somebody help me?

      Thanks

        • 1. Re: Validating an optionsgroup
          try67 MVP & Adobe Community Professional

          If the field reference is wrong (ie, f is null), that means you're not using the correct field name. Remember that JS is case-sensitive and that you must enter the field's name EXACTLY as it is, including any spaces or other special characters.

           

          Also, it's not a good idea to declare the same variable twice in the same function. In fact, that by itself might cause an error.
          So rename your variables f1 and f2, for example.

          • 2. Re: Validating an optionsgroup
            gkaiseril MVP & Adobe Community Professional

            I find using a function to get a field object is helpful because one can catch the error and report the error for correction.

             

            I would also not use the 'isBoxChecked" method since the widget number is based on the order of creation of each widget in the group. I would use the value of the group.

             

            function GetField(cName) {

            // get field object with error reporting;

            var oField = this.getField(cName);

            if (oField == null) app.alert("Error accessing field: " + cName, 1, 0);

            return oField;

            } // end GetField;

             

            want to call a function via a button to validate  optiongroups

            groupnames: option1 option2 ............

            field selection names: auswahl1, auswahl2, .......

            I used the following code:

             

            function opionsfelder()

            {

            var f = GetField("option1 auswahl1");

            if(f.isBoxChecked(0))

            {f.fillColor = color.red;

            }

            f = GetField("option1 auswahl2");

            if(f.isBoxChecked(0))

            {f.fillColor = color.green;

            }

            }

             

             


            • 3. Re: Validating an optionsgroup
              Fredy119 Level 1

              But I used this code in a former application with acrobat 9 and it worked.

              function TestLetter()

              {

              var f = this.getField("Option1.0");

              if(f.isBoxChecked(0))

              {f.fillColor = color.red;

              f.readonly = true;}

               

              var f = this.getField("Option1.1");

              if(f.isBoxChecked(0))

              {f.fillColor = color.green;

              f.readonly = true;

              punkte.value++;}

               

              var f = this.getField("Option1.2");

              if(f.isBoxChecked(0))

              {f.fillColor = color.red;

              f.readonly = true;}

               

              var f = this.getField("Option1.3");

              if(f.isBoxChecked(0))

              {f.fillColor = color.red;

              f.readonly = true;}

               

               

              var f = this.getField("Option2.0");

              if(f.isBoxChecked(0))

              {f.fillColor = color.red;

              f.readonly = true;}

               

              var f = this.getField("Option2.1");

              if(f.isBoxChecked(0))

              {f.fillColor = color.red;

              f.readonly = true;}

               

              var f = this.getField("Option2.2");

              if(f.isBoxChecked(0))

              {f.fillColor = color.green;

              f.readonly = true;

              punkte.value++;}

               

              var f = this.getField("Option2.3");

              if(f.isBoxChecked(0))

              {f.fillColor = color.red;

              f.readonly = true;}

              }

               

              I simply can't make it work with acrobat 10.1.10

              Were there significant changes?

              • 4. Re: Validating an optionsgroup
                try67 MVP & Adobe Community Professional

                You need to be more specific about the nature of the problem. What exactly goes wrong? Is there an error message in the console? If so, which one?

                • 5. Re: Validating an optionsgroup
                  gkaiseril MVP & Adobe Community Professional

                  Does the old form still work with Acrobat X or XI?

                   

                  Your scripts do  not exist by them selves, they interact with a form field, other fields, other actions, other scripts, etc.

                   

                  Can you supply a link to the form?

                   

                  The changes to Acrobat JavaScript are documented in the Acrobat JavaScript Reference.

                  • 7. Re: Validating an optionsgroup
                    try67 MVP & Adobe Community Professional

                    Do you mean the "Check" button? It's working fine for me...

                    • 8. Re: Validating an optionsgroup
                      Fredy119 Level 1

                      the widget number is based on the order of creation of each widget in the group.

                      That was the problem, I wasn't aware of that.