7 Replies Latest reply on Mar 13, 2008 4:14 AM by GerryIsHere

    Multiple selections in a ComboBox

    GerryIsHere Level 1
      Hi there!

      Is it possible to make multiple selections in a ComboBox ?
      i.e. make n consecutive selections and store them in an array
      or make n selections in the open list of the CB by using (for example) the click-Shift Key keystroke

      Purpose is to allow the user to select multiple different issues of a magazine with a maximum ease of use...
      (Code I use is attached below)

      Many thanks for your help!

      Best regards,
      Gerry


        • 1. Re: Multiple selections in a ComboBox
          GerryIsHere Level 1
          Maybe I can use a Checked List Component to send the Data from CBBUY...
          This will also offer the user the possibility of withdraw items for which the he/she changed his/her mind...

          But this is too complex for my abilities of coding...

          • 2. Re: Multiple selections in a ComboBox
            Level 7
            Hi Gerry - from the ComboBox component Help:

            A combo box allows a user to make a single selection from a pop-up list.

            You'll nee a list component or something else.

            --
            Dave -
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Re: Multiple selections in a ComboBox
              GerryIsHere Level 1
              Hi Dave!

              Thanks for replying.

              Yes I know that.
              But I think my question isn't well formulated...

              What I exactly mean is:
              "May I do consecutive selections in a CB, store them in an Array and then compile this list to use labels and data the array contains to write an invoice (with the labels) and calculate its amount (with the data)?"

              More, I don't know how to populate a List Component with a text file (like I do with a CB).

              Regards,
              Gerry
              • 4. Re: Multiple selections in a ComboBox
                Level 7
                >>"May I do consecutive selections in a CB, store them in an Array and then
                compile this list to use labels and data the array contains to write an
                invoice
                (with the labels) and calculate its amount (with the data)?"

                Gotcha - and sure you can.

                OK, let's see - you have this (sort of):

                var CBBUYListener:Object = new Object();
                CBBUYListener.change = function(evt:Object) {
                }

                I'd change that to something like this:

                var comboSelected = new Array();

                CBBUYListener= new Object();
                CBBUYListener.change = function(evt:Object){
                //first check to see if this item is already selected
                var didSelect = false;
                for(var i = 0; i < comboSelected.length; i++){
                if(comboSelected == evt.target.selectedIndex){
                trace("already selected this item");
                didSelect = true;
                break;
                }
                }
                //if not selected add this index
                if(!didSelect){
                comboSelected.push(evt.target.selectedIndex);
                }
                }
                CBBUY.addEventListener("change", CBBUYListener);


                What you get now is an array - comboSelected that will contain the selected
                indexes from the combo box - CBBUY.

                You want a sum of the data:

                function sumSelected(){
                var sum = 0;
                for(var i = 0; i < comboSelected.length; i++){
                sum += CBBUY.getItemAt(comboSelected
                ).data;
                }
                return sum;
                }

                You just get each item's data from the comboBox, at the index specified in
                the comboSelected array.


                --
                Dave -
                Head Developer
                http://www.blurredistinction.com
                Adobe Community Expert
                http://www.adobe.com/communities/experts/


                • 5. Re: Multiple selections in a ComboBox
                  GerryIsHere Level 1
                  Oh, my God! It works perfectly well! A thousand thanks!!!
                  I just duplicate the event listener: one for labels (which list will appear in the invoice) and one for the corresponding data (which will allow to compute the total amount as some issues cost twice the price of other).

                  I give you my code below.
                  Would please tell me if there is some simplification possible (i.e. all in one listener).

                  Thanks again, Dave, for the time dedicated to this question.

                  Best,
                  Gerry


                  • 6. Re: Multiple selections in a ComboBox
                    GerryIsHere Level 1
                    Silly of me!

                    I get the whole list displayed in a Dynamic Text Field all labels separated as expected by a comma but I can't get it as a list i.e. each label on its own line !!!

                    I tried toString() then split(",") but it has no effect.
                    What's wrong in my script?
                    (see below...)

                    Should I use a List Component to display User Selections ?
                    If yes, how do I transfer the selected Labels to it?

                    Regards,
                    Gerry


                    • 7. Re: Multiple selections in a ComboBox
                      GerryIsHere Level 1
                      Smart of me!

                      I delete the part of code contained in ADDED and simply wrote:
                      _root.traceBuyListFld.dataPtovider = comboSelectedLabel;

                      Please watch this forum because I'll post a sharp question about the List Component. Thank you!