2 Replies Latest reply on Feb 27, 2012 4:27 PM by star_cookie_queen

    Creating Adobe forms - JavaScript - Read Only / greyed out fields depending on user response

    star_cookie_queen Level 1

      Hopefully someone here can help me!!

       

      I need to create an Adobe form where the answer to the first question greys out and makes certain fields read only.

      I'm aware I need to write a Java Script for that, but how do I do that? I've been researching for days, and I just can't get it to work.

       

      Heres the example:

      The question is "Does this project fall under standard terms?" and if the answer is yes - then alot of questions need to be skipped, whereas if the answer is no, the questions need to be answered.

      I have tried having the first question as a checkbox, radio buttons and a dropdown menu with the "yes" and "no" options, but none of this seems to help.

       

      Can anyone help me understand what I need to do? PLEASE!?!?

       

      Thank you

        • 1. Re: Creating Adobe forms - JavaScript - Read Only / greyed out fields depending on user response
          George_Johnson MVP & Adobe Community Professional

          This is fairly straightforward and can be made a lot simpler if you give all of the optional field names a common prefix using a hierarchical naming scheme. For example, if you use a prefix of "optional" so that you have field names like "optional.name", "optional.address", "optional.email", etc. (note that the period character is critical here), you can set fields in the group to read-only with a single statement. Similarly, you can set the background color or reset the group, which is a good idea when disabling/enabling fields. For example:

           

          var f_prefix = "optional";
          
          // Get a reference to all of the "optional" fields
          var f = getField(f_prefix);
          
          // Set them all to readonly
          f.readonly = true;
          
          // Set the background color to gray
          f.fillColor = color.gray;
          
          // Reset all of the fields
          resetForm([f_prefix]);
          

           

          You can place this type of code in the Mouse Up event of a check box, something like:

           

          // Mouse Up script for check box
          // If checked, certain fields should be disabled
          
          var f_prefix = "optional";
          
          // Get a reference to all of the "optional" fields
          var f = getField(f_prefix);
          
          // Reset the optional fields
          resetForm([f_prefix]);
          
          if (event.target.value === "Off") {
              // Enable the optional fields
              f.readonly = false;
              f.fillColor = color.white;
          } else {
              // Disable the optional fields
              f.readonly = true;
              f.fillColor = color.gray;
          }
          
          • 2. Re: Creating Adobe forms - JavaScript - Read Only / greyed out fields depending on user response
            star_cookie_queen Level 1

            EXCELLENT! Thank you so much! Your the JavaScript Superman