5 Replies Latest reply on Aug 10, 2011 8:21 AM by LLNunez

    Field Value Range Script

    LLNunez

      I created a form in Acrobat Pro X and have a field in which I need to set a value range in a text field to be from .25 to 1.75. Any value lesser than .25 or greater than 1.75 will prompt (via the app.alert window) the user to enter a value within than range. I have the following script running in the "Run Custom Validation Script" in the field:

       

      if(event.value >= .25) && (event.value <= 1.75)
      {

       

      app.alert("ERROR: Please choose a value within .25 and 1.75.", 3);

       

      event.rc = false; 

      }

       

      However, the script doesn't seem to be working. Could somone please provide me with some guidance with the script above or provide a working script sample that can be used to get this value range validated?

        • 1. Re: Field Value Range Script
          gkaiseril MVP & Adobe Community Professional

          I see a couple of things right off the bat.

           

          Parentheses can are used to enclose logical test or group them. And you have created a compound logical test and properly enclosed them . But the 'if'' statement also requires parentheses to encapsulate the entire logical test and you do not have the enclosing parentheses for that statement.

           

          Did you get any errors on the JavaScript console for this coding?

           

          The next issue is the choice of comparison operators for the test. From your error message it appears you are saying a valid value is between 0.25 and 1.75 but you are testing for values between 0.25 and 1.75 to be the error.  It appears you want the error condition raised when the value is less than 0.25 OR greater than 1.75.

           

          And you will notice the conjunction for the test is the OR not the AND. You are testing for a non-contiguous range so you can not use the and conjunction. Because if one of the conditions for the error is meet the other condition of the test can not be meet.

           

          if ( (event.value < .25) | (event.value > 1.75)  ) {
          app.alert("ERROR: Please choose a value within .25 and 1.75.", 3, 0, "Validation Error");
          event.rc = false; 
          }

           

          It is easier to use the validation option of "The value is the range from: ___  to: ___".

          • 2. Re: Field Value Range Script
            MarkWalsh Level 4

            if((event.value >= .25) && (event.value <= 1.75)){
            //Valid
            } else {
            app.alert("ERROR: Please choose a value within .25 and 1.75.", 3);
            event.rc = false; 
            }

             

            You might also want to allow for an empty value- as it is now, clearing the form will give you the error message.

            • 3. Re: Field Value Range Script
              LLNunez Level 1

              How can I, within the script, allow for the value to be left blank and not get the error? I only want users to either enter a value within that range or, if left blank, they will not be prompted to enter a value.

              • 4. Re: Field Value Range Script
                MarkWalsh Level 4

                if (event.value != "") {
                // Put your validation code here

                 

                }

                • 5. Re: Field Value Range Script
                  LLNunez Level 1

                  Thank you much!!!

                   

                   

                  From:   MarkWalsh <forums@adobe.com>

                  To:     Omar Lopez Nunez <olopez@doe.k12.ga.us>

                  Date:   08/10/2011 11:09 AM

                  Subject:        Field Value Range Script

                   

                   

                   

                  if (event.value != "") {

                  // Put your validation code here

                   

                  }