7 Replies Latest reply on Jul 13, 2011 3:25 PM by Zulu Boy.

    Combo box selection hides fields

    Zulu Boy.

      Hi peeps,

       

      I have created a Questionnaire -form- with two sections (Sections A & B), where only one section needs to be completed, depending on the selection made in the Combo Box (comprised of Australian States).

       

      -ie. If You live in State x, answer Section B only.

       

      How do i hide unrequired section/fields, when a certain selection is made in the Combo Box?

       

      Pls help!

        • 1. Re: Combo box selection hides fields
          try67 MVP & Adobe Community Professional

          Make sure you tick the option to commit the selected item immediately in the combo-box's properties, and then use this script to show/hide your fields (set it as the custom validation script of the combo-box):

           

          if (event.value=="A") { // user selected "A"
              // make the A fields visible
              getField("A1").display = display.visible;

           

              // make the other fields hidden
              getField("B1").display = display.hidden;
              getField("C1").display = display.hidden;
          }
          else if (event.value=="B") { // user selected "B"
              // make the B fields visible
              getField("B1").display = display.visible;

           

              // make the other fields hidden
              getField("A1").display = display.hidden;
              getField("C1").display = display.hidden;
          }
          else if (event.value=="C") { // user selected "C"
              // make the C fields visible
              getField("C1").display = display.visible;

           

              // make the other fields hidden
              getField("A1").display = display.hidden;
              getField("B1").display = display.hidden;
          }

          1 person found this helpful
          • 2. Re: Combo box selection hides fields
            Zulu Boy. Level 1

            Thanx Try, i never really subscribe to a forum before, but this is good!

             

            Okay, i followed your instruction & used the script you suggested, makes perfect sense and seems to work, BUT only the first time..

             

            It will hide & show the appropriate fields for the first selection in the Combo Box, however, if you change selection, the hidden fields remain permanently hidden, even when i remove script & have no validation in the Combo Box. I have to go back and make fields visiable again, manually in thier prefs.

             

            So it seems to work but only for the first IF statement it runs.

             

            FYI: I ticked the "commit the selected item immediately" option.

             

            Here's a portion of my script, maybe I'm doing something wrong:

             

            if (event.value="select a State") { // user selected "select a State"

                // make all Q fields hidden

                getField("Q1").display = display.hidden;

                getField("Q2").display = display.hidden;

                getField("Q3").display = display.hidden;

                getField("Q4").display = display.hidden;

                getField("Q5").display = display.hidden;

                ....etc

            }

            else if (event.value="WA") { // user selected "WA"

                // make the WA fields visible

                getField("Q1").display = display.visible;

                getField("Q2").display = display.visible;

                getField("Q3").display = display.visible;

                getField("Q4").display = display.visible;

                getField("Q5").display = display.visible;

                ...etc.

             

                // make the other fields hidden

                getField("Q1b").display = display.hidden;

                getField("Q2b").display = display.hidden;

                getField("Q3b").display = display.hidden;

                getField("Q4b").display = display.hidden;

                getField("Q5b").display = display.hidden;

                ...etc.

            }

             

            Any ideas? Much appreciated.

            • 3. Re: Combo box selection hides fields
              try67 MVP & Adobe Community Professional

              You're making the common mistake of using the assignment operator ("=") instead of the comparison operator ("==") in your if-statments.

              • 4. Re: Combo box selection hides fields
                Zulu Boy. Level 1

                Thanks buddy, I'm learning, i got this.

                 

                I have another query which should be straight forward but i can't work it out... I'll raise a new discussion on it though.

                 

                Great help!

                ZB.

                • 5. Re: Combo box selection hides fields
                  Zulu Boy. Level 1

                  Hello again try67,

                   

                  Solving this problem has raised another smaller issue;

                   

                  The fields on my form/questionnaire are all 'Required' fields.

                   

                  Because the hidden fields have the Required Option selected it won't let submit form, prompting the usual "complete required fields (highlighted) before continuing" msg.

                   

                  how do i make the hidden fields exempt from the REQUIRED FIELD rule, - when hidden only ?

                   

                  thnx

                  ZB

                  • 6. Re: Combo box selection hides fields
                    try67 MVP & Adobe Community Professional

                    If this is caused by the built-in submit function, then you can't. But you

                    can adjust the script so that the hidden fields are not required.

                    1 person found this helpful
                    • 7. Re: Combo box selection hides fields
                      Zulu Boy. Level 1

                      Oh no! any hints as to how the script can be adjusted to accommodate this problem?

                       

                      Sorry for milking this, and thanx your help is highly appreciated.

                      zb