5 Replies Latest reply on Dec 15, 2016 6:51 AM by barba0987

    Map field-name to checkbox

    barba0987

      I am attempting to automatically check a checkbox when a hidden field has a  certain description.

      Very new to JavaScript.

      My validation script is:

       

      if (+event.value=="Text") this.getField("Text1 Checkbox").checkThisBox(0, True);

       

      Would someone please explain why this doesn't work and what the correct script should be.

      Any help is greatly appreciated.

       

       

       

       

       

        • 1. Re: Map field-name to checkbox
          try67 MVP & Adobe Community Professional

          Why did you add a plus-symbol before event.value? Do you know what that means?

          • 2. Re: Map field-name to checkbox
            George_Johnson MVP & Adobe Community Professional

            The + sign is used to easily convert a field value to a number explicitly, which is usually only done when the value will be used later in the script as a number, as when summing the values from several fields. (Blank fields values are returned as empty stings.) In this case, you're using the value as a string, so you should not only remove the +, but you should use the valueAsString property instead of the value property, something like:

             

            if (event.valueAsString == "Text") this.getField("Text1 Checkbox").checkThisBox(0, True);

             

            This will ensure that it always works. Note that the following would not:

             

            if (event.value == "012345") this.getField("Text1 Checkbox").checkThisBox(0, True);

             

            if the user entered "012345" since the leading zero would not be included when the result is automatically cast as a number and then compared to a string. It would work when using the valueAsString property.

            • 3. Re: Map field-name to checkbox
              try67 MVP & Adobe Community Professional

              Also, replace "True" with "true" (without the quotes).

              • 4. Re: Map field-name to checkbox
                George_Johnson MVP & Adobe Community Professional

                I have to correct this, since a lot of what I wrote isn't relevant in a validation script, since event.value is always a string and there is no event.valueAsString property. So a correct validation script would be:

                 

                if (event.value == "Text") this.getField("Text1 Checkbox").checkThisBox(0, true);

                • 5. Re: Map field-name to checkbox
                  barba0987 Level 1

                  Thank you for teaching me what the "+" does.  It is very important to me to not only know what I have done wrong but why it is wrong.  I appreciate it very much!