7 Replies Latest reply: Apr 18, 2012 1:56 PM by turbon5.0 RSS

    Validation Script Help

    turbon5.0

      Hi,

       

      This is my first time using Adobe to write any validation script.  Could someone provide an example script that would navigate the user to a text field and only let them fill in this text field if they check a Yes check box?

       

      Thanks

        • 1. Re: Validation Script Help
          George_Johnson CommunityMVP

          What do you mean by "navigate the user to a text field", exactly?

          • 2. Re: Validation Script Help
            turbon5.0 Community Member

            if the user clicks on the yes check box, i want the cursor to move to the text box to specify why they selected yes. if they didn't select yes, then don't let them type in that text box.

            • 3. Re: Validation Script Help
              George_Johnson CommunityMVP

              OK, here's what I would suggest as the Mouse Up script (not Validate script) for the check box:

               

               

              // Mouse Up script for check box
              (function () {
              
                  // Get a reference to the text field
                  var f = getField("text1");
              
                  // Reset the text field
                  f.value = f.defaultValue;
              
                  // Set the focus to the text field if check box is selected
                  if (event.target.value !== "Off") {
                      f.readonly = false;
                      f.setFocus();
                  } else {
                      f.readonly = true;
                  }
              
              })();
              

               

              Replace "text1" in the code above with the actual name of the text field you want to control.

              • 4. Re: Validation Script Help
                turbon5.0 Community Member

                Thanks, I appreciate the help.  I'll try that tomorrow and report back. Is there a place I can learn the basic codes? I am a little familiar with access, but this coding is different.

                • 5. Re: Validation Script Help
                  turbon5.0 Community Member

                  The code you provided partially works how I wanted it to.  Is there a way to make the text field unclickable until the user checks the yes box?  Also, if the no box is checked I wanted it to clear any info in the text box and make it unclickable again.  So basically there can only be info in the text box after the yes box has been checked.

                   

                  THANKS!

                  • 6. Re: Validation Script Help
                    George_Johnson CommunityMVP

                    I didn't realize you had another check box. You can place the same code (below) in the Mouse Up event of both check boxes:

                     

                    // Mouse Up script for check box
                    (function () {
                    
                        // Get a reference to the text field
                        var f = getField("text1");
                    
                        // Reset the text field
                        f.value = f.defaultValue;
                    
                        // Set the focus to the text field if check box is selected
                        if (event.target.value === "Yes") {
                            f.readonly = false;
                            f.setFocus();
                        } else {
                            f.readonly = true;
                        }
                    
                    })();
                    

                     

                    This assumes that the export value of the Yes check box is "Yes", and that the export value of the No check box is something else. The code set the field to read-only if the Yes check box is not selected, which makes makes it unclickable. The code also resets the text field whenever the script it called.

                    • 7. Re: Validation Script Help
                      turbon5.0 Community Member

                      THANKS! This worked perfect.