5 Replies Latest reply on Apr 20, 2011 3:14 PM by George_Johnson

    Simple Validation Script

    tiocabo

      I am new to Javascripting and I am trying to make a simple validation script for a Combo box. I have five choices in the pulldown including the default "Blank". I want the validation to require the use of any other choice other than "Blank". If Blank is left I want to pop an alert stating "Entry Required" before leaving the field. I have looked all over this forum and others and have'nt been able to get enough info on syntax using an "if" "else" "then" conditional to get my scripting attempts to work. Any help would be greatly appreciated.

        • 1. Re: Simple Validation Script
          George_Johnson MVP & Adobe Community Professional

          Normally for a blank item people use one of more spaces when setting it up. So that validate script should check for this and use app.alert to warn the user. Something like:

           

          if (event.value === " ") {  // single space
              app.alert("Entry required - Please make a different selection.", 3);
          }
          

           

          If your combo box item is the word "Blank", use that in the script above.

          • 2. Re: Simple Validation Script
            tiocabo Level 1

            Thank you George. This does wor

            k if the user enters the field, but if they don'

            t, it can remain blank. I tried to use an On Blur statement

            in actions but i must not have done it correctly because it has no affe

            ct. Any suggestions?

            • 3. Re: Simple Validation Script
              George_Johnson MVP & Adobe Community Professional

              You need to explain exactly how you want it to work. As long as the fields are active (not hidden or readonly), a user can always skip over them. It is possible to activate the subsequent fields only when a valid selection is made in the combo box, and deactivate them of not. Is that what you're wanting to do?

              • 4. Re: Simple Validation Script
                tiocabo Level 1

                George I'm sorry i

                didn't  explain exactly how i want it to work. i have

                this combo box the very first field on the tab sort when the form is opened in Reader

                . I want to make sure the user makes a valid entry in this

                field before he can go to any other field in the form.

                • 5. Re: Simple Validation Script
                  George_Johnson MVP & Adobe Community Professional

                  OK, the way to do that is what I mentioned before, but making the subsequent fields readonly and/or hidden unless a valid entry is made. It will be much easier to do this if you use a heirarchical naming convention so you can activate and deactivate with a single statement. For example, if you have five fields with names like:

                   

                  group1.text1

                  group1.check1

                  group1.text2

                  group1.check2

                  group1.combo1

                   

                  You can set their readonly property with a single statment:

                   

                  // Set the group to readonly

                  getField("group1").readonly = true;

                   

                  Otherwise, you have to execute a statement for each individual field:

                   

                  getField("text1").readonly = true;

                  getField("check1") .readonly = true;

                  //etc.

                   

                  So the script could be changed to:

                   

                  var fields = getField("group1");
                  
                  if (event.value === " ") {  // single space
                      app.alert("Entry required - Please make a different selection.", 3);
                      fields.readonly = true;
                  } else {
                      fields.readonly = false;
                  }
                  

                   

                  Though you should also reset the fields as well, which you can do with a resetForm statement.

                  1 person found this helpful