Skip navigation
Currently Being Moderated

Validation Script Help

Apr 17, 2012 6:54 PM

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

 
Replies
  • George Johnson
    11,664 posts
    Aug 11, 2002
    Currently Being Moderated
    Apr 17, 2012 9:07 PM   in reply to turbon5.0

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

     
    |
    Mark as:
  • George Johnson
    11,664 posts
    Aug 11, 2002
    Currently Being Moderated
    Apr 17, 2012 11:08 PM   in reply to turbon5.0

    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.

     
    |
    Mark as:
  • George Johnson
    11,664 posts
    Aug 11, 2002
    Currently Being Moderated
    Apr 18, 2012 12:56 PM   in reply to turbon5.0

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points