4 Replies Latest reply on Oct 31, 2014 1:38 PM by creativejoan0425

    About Dropdown list on change

    creativejoan0425 Level 1

      I have a Dialog, when I choose choice 2 the second dropdown with change to the list "1", "2","3","4","5","6","7","8","9","10","11", and choose choice 1 the list should be "A","B","C","D","E","F","I","J", but now when I choose choice 1 or 2, the list will not change

      var myObject;

      var mySelArray = null;

      var myDialog = new Window("dialog", "Test_v1.0");

      myDialog.alignChildren = ["fill","fill"];

      var g1 =myDialog.add ("group");

            g1.alignChildren = "top";

       

       

      var myPanel = g1.add ("panel");

            myPanel.orientation = "column";

            myPanel.alignChildren = "right";

       

       

      var myLangGroup = myPanel.add ("group");

      var group1 = myLangGroup.add ("group");

            group1.add ("statictext", [0, 0, 60, 20], "Language:");

      var group2 = myLangGroup.add ("group");

      var myDropdown1 = group2.add("dropdownlist",undefined, ["Choice 1", "Choice 2"]);

            myDropdown1.itemSize = [200,20];

            myDropdown1.active = true;

            myDropdown1.selection = 0;

       

       

      var myGlobalListGroup = myPanel.add ("group");

            myGlobalListGroup.alignChildren = ["fill","fill"];

             myGlobalListGroup.alignChildren = "left";

       

       

      var group5 = myGlobalListGroup.add ("group");

            group5.add ("statictext", undefined, "Change To:");

      var group6 = myGlobalListGroup.add ("group");

            group6.orientation = "column";

            group6.alignChildren = "right";

           var myArray1 = ["A","B","C","D","E","F","I","J"];

           var myArray2 = ["1", "2","3","4","5","6","7","8","9","10","11"];

      //~                 }//end of loop

      if(myDropdown1.selection == 0){

              mySelArray = myArray2;

      }

      else if(myDropdown1.selection == 1){

              mySelArray = myArray1;

      }   

      var myDropdown2 = group6.add("dropdownlist",undefined, mySelArray);

            myDropdown2.itemSize = [200,20];

            myDropdown2.active = true;

       

       

      var mySearchRangeGroup = myPanel.add ("group");

            mySearchRangeGroup.alignChildren = ["fill","fill"];

            mySearchRangeGroup.alignChildren = "left";

       

       

      var group7 = mySearchRangeGroup.add ("group");

             group7.add ("statictext", undefined, "Search Range:");

      var group8 = mySearchRangeGroup.add ("group");

            group8.orientation = "column";

            group8.alignChildren = "right";

       

       

      var myDropdown3 = group8.add("dropdownlist",undefined, ["i", "ii", "iii"]);

            myDropdown3.itemSize = [200,20];

            myDropdown3.active = true;

       

       

       

       

      var myRangeGroup = myDialog.add ("group");

            myRangeGroup.alignChildren = ["fill","fill"];

           myRangeGroup.alignChildren = "left";

      var group9 = myRangeGroup.add ("group");

            group9.orientation = "column";

            group9.alignChildren = "left";

       

       

      var myRange1 = group9.add("radiobutton", undefined, "with Markup");;

      var myRange2 = group9.add("radiobutton", undefined, "without Markup");;

          myRange1.value = true;

          myRange1.active = true;

       

      var myBottomGroup =  g1.add ("group");

           myBottomGroup.alignChildren = ["fill","fill"];

            myBottomGroup.orientation = "column";

            myBottomGroup.add ("button", undefined, "OK");

            myBottomGroup.add ("button", undefined, "Cancel");

       

       

      //----------------------------------------end of Dialog------------------------------------------------------

      //-----------------------------------------onChange ---------------------------------------------------------

      myDropdown1.onChange = function() { 

      switch (myDropdown1.selection.index) { 

          case 0 : 

          mySelArray =myArray2;

          return mySelArray;

          break; 

          case 1 : 

          mySelArray= myArray1;

          return mySelArray;

      //-----------------------------------------onChange ---------------------------------------------------------

      var myWindow = myDialog.show();

      if (myWindow == true){

       

       

      }

        • 1. Re: About Dropdown list on change
          cchimi Level 2

          You're not actually repopulating the list. I use a little function to populate a box that takes items. Here's a simplified version:

           

              function fillLBox(funcLBox, funcArray){
                  if (!(funcArray instanceof Array)) {}
                  else{
                      for (var i = 0; i < funcArray.length; i++){
                          var myListing = funcArray[i];
                          if(myListing instanceof String){
                              funcLBox.add("item", myListing);
                          }
                          else{}
                      }
                  }
              }
          

          then, in your onChange function, do something like this:

           

          myDropdown1.onChange = function() {
          myDropdown2.removeAll();
          switch (myDropdown1.selection.index) {
              case 0 :
              fillLBox(myDropdown2, myArray2);
              break;
              case 1 :
              fillLBox(myDropdown2, myArray1);
          }
          }
          
          • 2. Re: About Dropdown list on change
            creativejoan0425 Level 1

            I try your script, but when I choose Choice 2 , it will have a dropdownlist but it is blank

            ttt.jpg

            • 3. Re: Re: About Dropdown list on change
              cchimi Level 2

              Sorry, I forgot to update one line. Change

               

              if(myListing instanceof String){ 
              

               


              to


              if(typeof myListing == "string"){ 


              I really wish I could edit my posts to make this clearer, but that should do it.

              • 4. Re: Re: About Dropdown list on change
                creativejoan0425 Level 1

                Cool, it work, thx