4 Replies Latest reply on Feb 25, 2008 10:27 AM by (J_Rahmaan)

    JavaScript Validation in Adobe Professional 8

      Hi all,

      I'm a newbie to Adobe stuff, forms, and their "validation" concept using Java Scripts. My client has an employee that is building a page for their website to obviously, get information into a database. However, they want to apply a validation to date fields... I know that Adobe has some built-in validations, but the validation they want is to prevent FUTURE dates (limited ex: to just month/year, and also prevent really OLD dates (like over 100 years)...

      So, I have this java script that accepts a text value parameter which gets parsed and does this validation ... no problem. However, how do I get Adobe Professional to recognize my call to it.

      For simplicity purposes, I even have the first line in the function to just return false;... so its something like this...

      function validDate(passdate)
      { return false; }

      obviously nothing tricky and actual code is longer to handle parsing, numeric validation, etc... But how to incorporate this within Adobe.

      Lets get VERY basic here... I have a simple form with 1 field... the textbox field... And I right-click on it, go to properties, click on the validation tab, and radio-button for validate via javaScripting. I pasted the code in there that represents the function, but it obviously does nothing. I'm not going to bother confusing the answers based on other crap I've found to be lacking of any substance, so any good direction / samples would be GREATLY appreciated.


        • 1. Re: JavaScript Validation in Adobe Professional 8
          Patrick Leckey Level 3
          Just post the actual code in there, not in the form of a function (whatever your code inside the function would be).

          Think of it as already having a validate() function, and whatever you put in is the body of that function.
          • 2. Re: JavaScript Validation in Adobe Professional 8
            Level 1
            So, now, to expand on why I wanted to have it as a function called from the textbox... Its a medical questionnaire, and has litterally over 100 date fields based on yes/no Q&A responses... I didn't want to add this code for all 100 date fields.

            So, given this the case, I know typically a validation event will need to return a true or false. Also, given I have the sample function, I tried to have it do a simple

            return validDate( this.value );

            but get a compile error with the "RETURN" statement.
            • 3. Re: JavaScript Validation in Adobe Professional 8
              gkaiseril MVP & Adobe Community Professional
              I believe Acrobat JavaScript functions can return a value that can be used to set the event's return code to indicate a valid or invalid entry:

              // your doucment level funciton
              function validDate(sDate, cFormat) {
              var bValid = true; // assume a valid date
              // code to process date
              if (errorTest == true) bValid = false;
              return bValid;
              } // end function

              event.rc = validDate(event.value);
              • 4. Re: JavaScript Validation in Adobe Professional 8
                If you don't want to use the debugger with breakpoints et al, use app.alert in your function to test whether it is being called.

                Adobe JavaScript has a lot of nuances that are not compatible with "normal" JS but you should still be able to get a function call to work by adding the action "Run a JavaScript" to the focus event of your form fields (you do this in the ACTION tab) and adding your function call there. If your function isn't Adobe JS compatible though you're going to run into problems.