1 Reply Latest reply on Dec 11, 2017 1:27 AM by try67

    Need help validating a field entry after using java script

    davidt36293775

      Good evening, everyone!

       

      Here's the problem.  I have a numeric field which is filled in by the end user.  After that question, the user is asked to select from a drop down menu of text options.  If the selected text option is "Text A" then the numeric field should be validated to a max value of 12.  If "Text A" is NOT selected then the max value of the field is 20.  I'm trying to use the following script to validate an if/then statement.

       

      The script works well when the text is selected first, however, if the numeric value is filled first then the script does not validate the numeric field to 12 unless the user goes back into the box..  Is there a way to have the numeric field automatically correct to 12 if the value is greater than 12 if Text A is selected after the numeric field is populated?  Any help is appreciated!

      // Custom Validate script of a numeric text field

      (function () {

       

           // Get the value of the TextChoices field, as a string

           var sTextChoices = getField("TextChoices").valueAsString;

       

           // Alter this field's value if necessary

           if (+event.value > 12 && sTextChoices === "Text1") {

               event.value = 12;

           }

       

      })();