13 Replies Latest reply on May 4, 2011 9:05 AM by burlingtonnow

    Corrective Java Script

    burlingtonnow

      Hi, I am having problem with this script.

       

      varflVal =parseFloat (This.get Field ("STR"). value);

      if (falVal <= 1.99)  {

                                 event. value = 1 ;

      }   else   if (flVal <= 2.50)  {

                                 event. value = 2 ;

      }   else   if (flVal <= 3.50)  {

                                 event. value = 3 ;

      }   else   if (flVal <= 4.25)  {

                                 event. value = 4 ;

      }   else      {

                                 event. value = 5 ;

      }

       

      This script works but when the calculation equals 1.99, 3.50, 4.25 exactly the event.value rounds up. and I don't want it to round up. I want it to equal the event. value number I perscribed.

       

      I tried this script but I get an error that read invalid XML name 4:at 5

       

      varflVal =parseFloat (This.get Field ("STR"). value);

      if (falVal <= 1.99)  {

                                 event. value = 1 ;

      }   else   if (flVal >=2.00&&<= 2.50)  {

                                 event. value = 2 ;

      }   else   if (flVal >=2.51&&<= 3.50)  {

                                 event. value = 3 ;

      }   else   if (flVal >=3.51&&<= 4.25)  {

                                 event. value = 4 ;

      }   else      {

                                 event. value = 5 ;

      }

       

      Can you please help me with my second script. I want the calculation that equals 2.50 to be a 2 , 3.50 to be a 3 ,and  4.25 to be a 4 , and anything over 4.25 to equal a 5

       

      Thanks for the help!!

        • 1. Re: Corrective Java Script
          George_Johnson MVP & Adobe Community Professional

          Before anything else, this bit of code:

           

          This.get Field ("STR"). value

           

          should fail, so it should be:

           

          this.getField("STR").value;

          • 2. Re: Corrective Java Script
            George_Johnson MVP & Adobe Community Professional

            Next, this bit of code:

             

            (flVal >=2.00&&<= 2.50)

             

            Should be:

             

            (flVal >= 2 && flVal <= 2.50)  {

             

            and the same for the other similar parts.

            • 3. Re: Corrective Java Script
              burlingtonnow Level 1

              I think I solved my problem.....I found out that There isn't a =< operator in AS3 .  So I took out the = sign and applyed this script

               

              varflVal =parseFloat (This.get Field ("STR"). value);

              if (falVal < 2.00)  {

                                         event. value = 1 ;

              }   else   if (flVal < 2.51)  {

                                         event. value = 2 ;

              }   else   if (flVal < 3.51)  {

                                         event. value = 3 ;

              }   else   if (flVal < 4.26)  {

                                         event. value = 4 ;

              }   else      {

                                         event. value = 5 ;

              }

               

              and this seems to work.  I would still like to hear a reply.

               

               

              Again thank you

              • 4. Re: Corrective Java Script
                George_Johnson MVP & Adobe Community Professional

                You don't use AS3 in Acrobat, it's JavaScript (ECMAScript) 1.2-1.8, depending on what version of Acrobat is used. JavaScript has both the <= and >= comparison operators, but they have to be used correctly.

                 

                You should set your JavaScript preferences to show the console when an error is triggered, to help with your debugging.

                • 5. Re: Corrective Java Script
                  burlingtonnow Level 1

                  Thanks George.  Okay first I missed type This. get Field it is this.get Field.

                   

                  Secondly....I got that error message invalid XML name for line 5.  So I googled Invalid XML name Javascript Boolan. I saw that someone had a similar problem so I took out the = sign and made <=1.99  , < 2.00 but when I did a calculation that equal 1.99 it rounded up to a 2....and I don't want that.

                   

                   

                  Can you send me a script that will work for my problem

                  • 6. Re: Corrective Java Script
                    gkaiseril MVP & Adobe Community Professional

                    White space maybe important to separate the 'var' from the name of the variable being defined.

                     

                    Check the spelling of the variable name.

                     

                    Are you using the predefined "Format"  tab formats?

                     

                    Are you sure your computed result is only 1.99 and not 1.995?

                     

                    console.show();
                    console.clear();

                    var flVal = parseFloat(this.getField("STR").value);

                    if(isNaN(flVal)) flVal = 0; // force non-numbers to zero

                    console.println('flVal: ' + flVal);

                    switch(true) {
                    case (flVal < 2):
                         event.value = 1;
                    break; // exit
                    case (flVal < 2.51):
                         event.value = 2;
                    break; // exit
                    case (flVal < 3.51):
                         event.value = 3;
                    break; // exit
                    case (flVal < 4.26):
                          event.value = 4;
                    break; // exit
                    default:
                          event.value = 5 ;
                    break; // exit
                    } // end switch

                    console.println('event.value set to: ' + event.value)

                    • 7. Re: Corrective Java Script
                      burlingtonnow Level 1

                      Hi,

                       

                       

                      Here is my rating system that I need the script to adhear to:

                       

                       

                      1 = [1.00 - 1.99]

                      2 = [2.00 - 250]

                      3 = [2.51 - 3.50]

                      4 = [3.51 - 4.25]

                      5 = [4.26 - 5.00]

                       

                      this script you gave me does not work fully.

                       

                      var flVal = parseFloat(this.getField("STR").value);
                      console.println('flVal: ' + flVal);
                      switch(true) {
                      case (flVal < 2):
                           event.value = 1;
                      break; // exit
                      case (flVal < 2.51):
                           event.value = 2;
                      break; // exit
                      case (flVal < 3.51):
                           event.value = 3;
                      break; // exit
                      case (flVal < 4.26):
                            event.value = 4;
                      break; // exit
                      default:
                            event.value = 5 ;
                      break; // exit
                      } // end switch

                       

                      When the calculation come out to be 3.51 the event.value is should be a 4 not a 3

                       

                      I hope this helps

                      • 8. Re: Corrective Java Script
                        burlingtonnow Level 1

                        Rating Scale:

                         

                        1 = [1.00 - 1.99]

                        2 = [2.00 - 2.50]

                        3 = [2.51 - 3.50]

                        4 = [3.51 - 4.25]

                        5 = [4.26 - 5.00]

                         

                         

                        This is the Rating Scale I am using

                        • 9. Re: Corrective Java Script
                          gkaiseril MVP & Adobe Community Professional

                          Is your value for the comparison 3.51 or is in in the range of 3.505 - 3.509?

                           

                          What is your Acrobat JavaScript console showing?

                           

                          The script I provided will display the actual value and not the displayed value, which is rounded.

                           

                          Do you need to round the results of your calculation?

                           

                          What happens with values less than 1 and greater than 5?

                          • 10. Re: Corrective Java Script
                            burlingtonnow Level 1

                            In the script you gave me. I changed the 3.51 to 3.50 and that seem to work.

                             

                            to answer you question the cut off is  A 3 should be 2.51 - 3.50 and a 4 should be 3.51 - 4.25

                             

                            please look at my rating scale.  That is what I want the number to be.

                            • 11. Re: Corrective Java Script
                              gkaiseril MVP & Adobe Community Professional

                              If you are performing calculations, the displayed value will not always equal the value used by JavaScript. It might be a good idea to round the value used in the script to match the displayed value. You might also need to trap values outside of the rating scale.

                               

                              var flVal = util.printf("%,1 .2f", (this.getField("STR").value));

                              switch(true) {
                              case (flVal == 0):
                                   event.value = '';
                              break; // exit
                              case ((flVal > 4.25) && (flVal <= 5)):
                                    event.value = 5;
                              break; // exit
                              case ((flVal > 3.5) && (flVal <= 4.25)):
                                    event.value = 4;
                              break; // exit
                              case ((flVal > 2.5) && (flVal <= 3.5)):
                                   event.value = 3;
                              break; // exit
                              case ((flVal >= 2) && (flVal <= 2.5)):
                                   event.value = 2;
                              break; // exit
                              case ((flVal >= 1) && (flVal < 2)):
                                   event.value = 1;
                              break; // exit
                              default:
                                   event.value = '';
                                   app.alert('Invalid score: ' + flVal , 1, 0, "Score Error");
                              break;
                              } // end switch

                              • 12. Re: Corrective Java Script
                                burlingtonnow Level 1

                                Thank You George...you last script worked.

                                 

                                Again Thank you.

                                • 13. Re: Corrective Java Script
                                  burlingtonnow Level 1

                                  George,

                                   

                                   

                                  The script is working but when I want to start over by un-clicking my calculation I am getting a WARNING JavaScript Window-Score Error...in the box it says

                                  Invalid Score.

                                   

                                  Can you tell me how to make this warning go away???