7 Replies Latest reply on Nov 3, 2009 12:54 PM by Tilquinith

    ? List Box Selections to Show/hide form fields

    Tilquinith Level 1

      Ok, so I want to use a list box to control which form fields on my page are visible or hidden. I have no problem creating the list box and adding items to the list but haven't been able to figure out what scripting I need to connect each selection to the relevant form field I want it to control.


      So essentially I want to know what javascript is necesary to be able to let the end user select one or more items from the listbox and have those fields become visible on the page. How do I do this?

        • 1. Re: ? List Box Selections to Show/hide form fields
          pguerett Level 6

          The 1st thing is to get the value that the user selected in the listbox and to choose an event to execute your code. I woudl recommend the exit event rather than the change event (the user has committed to the value when he exits the field). To get the value of the listbox use the command:




          The "this" refers to the object that  is running the script.


          Now to make other objects visible or invisible you can use the objects name and then the presence property. So the command woudl look like this:


          ObjectName.presence = "visible"


          Now that you have the basic commands you will need to evaluate what the user chose and act accordingly. So the command woudl look like this:


          if (this.rawValue == "thing you want to check for"){

               Fieldname.presence = "visible";

               FieldName2.presence = "visible";

          } else {

               Fieldname.presence = "invisible";

               Fieldname2.presence = "invisible"



          If you have lots of selections in th edrop down list then you may want to look at a Select statement instead of nesting many if statements.



          1 person found this helpful
          • 2. Re: ? List Box Selections to Show/hide form fields
            Tilquinith Level 1

            This is helpful but when I try it, it doesn''t work. How do I script the select statement. I'm using a list box, not a drop down list just to clarify. I want the user to be able to make multiple selections from the list. How do I write the script so that it checks for each item thats selected and then makes that item visible or hidden depending on whether its been selected?


            I've attached an example of the document, If you could look at it and tell me what I'm doing wrong I'd appreciate it.

            • 3. Re: ? List Box Selections to Show/hide form fields
              Tilquinith Level 1

              Ok so here is my work up to this point. The biggest sticking point is the listbox problem I'm having. I need the user to be able to select multiple items from the list box and have those fields revealed or hidden based on what is or isn't selected. So far it only half works. When you make the selections you want and then tab to the next field it hides all the fields associated with the list box and doesn't reveal the selected ones.


              Also at the end of the second page is a button that is supposed to create another instance of the first two pages. And as far as I can tell there should be no limit to it. However this does not work at all.


              And just because I'm guessing it will become a problem, assuming I do at some point get the add pages button working. How do I make sure the reset form button only applies to the two page spread that its located on?


              I've included the file I'm working on. I'd appreciate any help or advice you have on how to make this work and show me what I'm doing wrong.





              • 4. Re: ? List Box Selections to Show/hide form fields
                pguerett Level 6

                If you create a multiselct list then the rawValue will return a string separated by Carriage returns so all of your fi statements will never match. You can use javascript to split the string into individual values and put them into an array. Then test each individual string in the array through your if statements.


                The code wouls look something like this:


                //set a var to hold the selections

                var temp =this.rawValue;

                //split the selection based on the CR char
                var tempArray = temp.split("\x0A");
                //debug step to make sure we got all the selections


                //run through each selection
                for (i=0;i<=tempArray.length;i++){
                temp = tempArray[i];
                //debug step to see that we have a single selection


                //Note that you must change your code to test the temp variable instead of the selection in the list
                if (temp == "Aura")
                  {flexsubform.aura.presence = "visible";}
                  {flexsubform.aura.presence = "hidden";}

                if (temp == "Defensive Abilities")
                  {flexsubform.defensiveabilities.presence = "visible";}

                1 person found this helpful
                • 5. Re: ? List Box Selections to Show/hide form fields
                  Tilquinith Level 1

                  I tried your code, and for the second debug step I get back an alert that says "undefined". This is of course causing the rest of it to not work. But I'm not sure what is wrong about it. I'm not familiar with working with arrays, and the books I've looked at so far aren't terribly helpful.


                  Also I asked about it in a previous post but at the bottom of the last page in my pdf I put a button to add an instance of the first two pages, effectively to continue making the pdf longer if needed. I added the script I found in my book but it doesn't work. Either I'm doing it wrong or what I got from my book is incomplete. Could you look at that and see what I've done wrong as well?


                  I do really appreciate the help you've provided so far, it's been very illuminating.



                  • 6. Re: ? List Box Selections to Show/hide form fields
                    pguerett Level 6

                    Had a look at your code and you ended the for loop before you ran all of your tests. The if statements musty be inside the for loop. I modified your code (reformatted it a bit so it is easier to read) and included it here.



                    • 7. Re: ? List Box Selections to Show/hide form fields
                      Tilquinith Level 1

                      What you did works, sort of. When you select more than one item it runs through them and only the last selection works. Although if I hide all the "else" statements and change all the starting qualities of those form fields to "hidden", then it works. I had hoped to be able to show and hide with the multi select list box but maybe thats not easily possible. Do you know of a way to not just hide the previous after checking the next?


                      But otherwise thankyou very much for your help, you're a lifesaver.