2 Replies Latest reply on Oct 20, 2017 6:13 AM by davidt36293775

    Need help with javascript and if/then/else statements

    DAT0728

      Hello everyone!   I have searched this forum for days and tried many things but cannot find a workable solution to my problem.  My javascripting skills are novice at best.

       

      I have created a numerical free text box "NumberValue" and a dropdown menu "TextChoices" with 5 text choices (ie Text1, Text2, Text3, Text4, Text5).  IF the user selects Text1 AND the previous numerical box "NumberValue" is >12 THEN make the "NumberValue" = 12.  IF the user selects Text1 AND the "NumberValue" is <12 THEN make "NumberValue" = the users input.  IF the user selects any other text choice THEN "NumberValue" = the users input.

       

      Any advice other than closing the program and walking away?

        • 1. Re: Need help with javascript and if/then/else statements
          George_Johnson MVP & Adobe Community Professional

          You could use a custom Validate script for the NumberValue field, something like this:

           

          // 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;

               }

           

          })();

          1 person found this helpful
          • 2. Re: Need help with javascript and if/then/else statements
            davidt36293775

            George,

             

            YOU, sir, are amazing!  Thank you!  Your script opens up so many options.  One followup question though.  I've noticed upon testing that if I were to populate the numeric text field first THEN select the proper text choice from the dropdown, the numeric text field still maintains the user entered value.  The script works great if the text choice was selected first then the numeric text field was populated.

             

            Is there an option to have the numeric field update if the appropriate dropdown text choice is chosen after the numeric text field population?