12 Replies Latest reply on Apr 6, 2011 4:06 AM by try67

    Reposition field using combo box value

    MadMich Level 1

      I have an error at line 18 on this code?

      When a combo box selection is made it is supposed to move the 3 fields?

      Any advice would be greatly appreciated.

       

      var d = this.getField("Step.0.1");
      var e = this.getField("Step.1.1");
      var f = this.getField("Step.2.1");

       

      var aFields = ["Step.0.1", "Step.1.1", "Step.2.1"];

       

      switch (event.value) {

       

      case "0":
          d.rect = [474.31298828125,505.59600830078125,602.52197265625,450.64898681640625];
          e.rect = [474.31298828125,449.385986328125,602.52197265625,394.4389953613281];
          f.rect = [474.31298828125,393.1759948730469,602.52197265625,338.22900390625];
      case "10%":
          for(i = 0; i < aFields.length; i++) {
          var aRect = aFields.rect;  
          aRect[1] += -10;      
          aRect[3] += -10;      
          aFields.rect = aRect;  
          }
      case "20%":
          for(i = 0; i < aFields.length; i++) {
          var aRect = aFields.rect;  
          aRect[1] += -20;      
          aRect[3] += -20;      
          aFields.rect = aRect;   
          }
      case "30%":
          for(i = 0; i < aFields.length; i++) {
          var aRect = aFields.rect;
          aRect[1] += -30;  
          aRect[3] += -30;   
          aFields.rect = aRect;  
          }
      default:
          d.rect = [474.31298828125,505.59600830078125,602.52197265625,450.64898681640625];
          e.rect = [474.31298828125,449.385986328125,602.52197265625,394.4389953613281];
          f.rect = [474.31298828125,393.1759948730469,602.52197265625,338.22900390625];
          }

        • 1. Re: Reposition field using combo box value
          try67 MVP & Adobe Community Professional

          You need to add a "break" command at the end of each case block.

           

          The error is that you're trying to access aFields.rect instead of

          this.getField(aFields[i]).rect

          • 2. Re: Reposition field using combo box value
            MadMich Level 1

            Cheers for your help, i've added your comments but still get an error at line 18?

             

            Here is the code amended:

             

            var d = this.getField("Step.0.1");
            var e = this.getField("Step.1.1");
            var f = this.getField("Step.2.1");

             

            var aFields = ["Step.0.1", "Step.1.1", "Step.2.1"];

             

            switch (event.value) {

             

            case "0":
                d.rect = [474.31298828125,505.59600830078125,602.52197265625,450.64898681640625];
                e.rect = [474.31298828125,449.385986328125,602.52197265625,394.4389953613281];
                f.rect = [474.31298828125,393.1759948730469,602.52197265625,338.22900390625];
                break;
            case "10%":
                for(i = 0; i < aFields.length; i++) {
                var aRect = this.getField(aFields[i]).rect;  
                aRect[1] += -10;      
                aRect[3] += -10;      
                this.getField(aFields[i]).rect = aRect;  
                }
                break;
            case "20%":
                for(i = 0; i < aFields.length; i++) {
                var aRect = this.getField(aFields[i]).rect;  
                aRect[1] += -20;      
                aRect[3] += -20;      
                this.getField(aFields[i]).rect = aRect;   
                }
                break;

             

            case "30%":
                for(i = 0; i < aFields.length; i++) {
                var aRect = this.getField(aFields[i]).rect;
                aRect[1] += -30;  
                aRect[3] += -30;   
                this.getField(aFields[i]).rect = aRect;  
                }
                break;

             

            default:
                d.rect = [474.31298828125,505.59600830078125,602.52197265625,450.64898681640625];
                e.rect = [474.31298828125,449.385986328125,602.52197265625,394.4389953613281];
                f.rect = [474.31298828125,393.1759948730469,602.52197265625,338.22900390625];
                }

            • 3. Re: Reposition field using combo box value
              try67 MVP & Adobe Community Professional

              Post the exact error message you're getting.

              • 4. Re: Reposition field using combo box value
                MadMich Level 1

                Here is the error, (sorry since i added the bits the error line has moved up!)

                 

                JavaScript error at line 17: SyntaxError: illegal character

                16:. Fix it?

                • 5. Re: Reposition field using combo box value
                  try67 MVP & Adobe Community Professional

                  Not sure if it's that, but in the last parameter of d.rect you have a space

                  in the middle of the number.

                  • 6. Re: Reposition field using combo box value
                    MadMich Level 1

                    I think it's just the way it's viewing, still no luck!

                     

                    My coding must be getting better, i thought it may have been a more obvious mistake.

                    • 7. Re: Reposition field using combo box value
                      MadMich Level 1

                      I think I've fixed it but i cant seem to get it to work outside the console?

                      The code is under custom validation scripts in a combo box, and is set to move 3 boxes in 10 increments.

                      When i make a selection nothing happens?

                       

                      Here is my amended script, any ideas would be appreciated.

                       

                      var d = this.getField("Step.0.1");

                      var e = this.getField("Step.1.1");

                      var f = this.getField("Step.2.1");

                       

                      var aFields = [d,e,f];

                       

                      switch (event.value) {

                       

                      case "0":

                      d.rect = [474.31298828125,505.59600830078125,602.52197265625,450.6489868164062 5];

                      e.rect = [474.31298828125,449.385986328125,602.52197265625,394.4389953613281];

                      f.rect = [474.31298828125,393.1759948730469,602.52197265625,338.22900390625];

                      break;

                       

                      case "10%":

                      for(i = 0; i < aFields.length; i++) {

                      var aRect = aFields[i].rect;

                      aRect[1] -= 10;

                      aRect[3] -= 10;

                      aFields[i].rect = aRect}

                      break;

                       

                      case "20%":

                      for(i = 0; i < aFields.length; i++) {

                      var aRect = aFields[i].rect;

                      aRect[1] -= 20;

                      aRect[3] -= 20;

                      aFields[i].rect = aRect}

                      break;

                       

                      case "30%":

                      for(i = 0; i < aFields.length; i++) {

                      var aRect = aFields[i].rect;

                      aRect[1] -= 30;

                      aRect[3] -= 30;

                      aFields[i].rect = aRect}

                      break;

                       

                      default:

                      d.rect = [474.31298828125,505.59600830078125,602.52197265625,450.6489868164062 5];

                      e.rect = [474.31298828125,449.385986328125,602.52197265625,394.4389953613281];

                      f.rect = [474.31298828125,393.1759948730469,602.52197265625,338.22900390625];

                       

                      • 8. Re: Reposition field using combo box value
                        try67 MVP & Adobe Community Professional

                        It doesn't make sense that this will work in the console (there's no event.value) and not from the field itself.

                        There must be something else wrong.

                        • 9. Re: Reposition field using combo box value
                          MadMich Level 1

                          Hi,

                          Sorry I only used part of the code in the console.

                          As you can gather i'm still stuck?

                          • 10. Re: Reposition field using combo box value
                            try67 MVP & Adobe Community Professional

                            I can't help you if I don't know which exact code you're using, from which

                            context, and what error messages you're getting.

                            • 11. Re: Reposition field using combo box value
                              MadMich Level 1

                              Hi try67,

                               

                              This is part of my code i checked in the console:

                               

                              var d = this.getField("Step.0.1");

                               

                              var e = this.getField("Step.1.1");

                               

                              var f = this.getField("Step.2.1");

                               

                               

                               

                              var aFields = [d,e,f];

                               


                              for(i = 0; i < aFields.length; i++) {

                               

                              var aRect = aFields[i].rect;

                               

                              aRect[1] -= 10;

                               

                              aRect[3] -= 10;

                               

                              aFields[i].rect = aRect}

                               

                              I don't understand how this part works in the console but not as part of the entire script (submitted above which errors at "

                              var aRect = aFields[i].rect;").

                              The error code  is:

                              SyntaxError: illegal character
                              15:AcroForm:Subject.3:Validate
                              SyntaxError: illegal character
                              15:

                               

                              The script as mentioned is part of a combo box vlidation script.

                               

                              Thanks for your time, I'd upload the pdf example (as i have on another site) but don't seem to have the option on this site?

                              • 12. Re: Reposition field using combo box value
                                try67 MVP & Adobe Community Professional

                                I put this script in a button action and it works fine.