2 Replies Latest reply on Sep 14, 2010 1:36 AM by Pontus Uggla

    Set dropdown indexes?

    Pontus Uggla Level 1

      Can i. like i do in html, set the indexes of a selectbox manually?



           <option value="1">Foo</option>

           <option value="2">Bar</option>



      What i do now is to set the index first and pregmatch it like:


      .add('item', '1. Foo');

      .add('item', '2. Bar');


      But its not very nice.


      From what i can tell index is protected. Is there a way around it?



        • 1. Re: Set dropdown indexes?
          Marijan Tompa [tomaxxi] Level 4



          Yeah, It's typical HTML stuff. You can't do it in InDesign.

          You can retrieve index number from selected item like this:


          var myList = ["Item 1","Item 2","Item 3","Item 4"];
          var myWin = new Window('dialog', 'Test Dropdown');
          var myDrop = myWin.add('dropdownlist', undefined, myList);
          // get values
          myDropIndex = myDrop.selection.index;
          myDropValue = myDrop.selection;


          Or, you can create two dimensional array, pust first values into dropdown, and depending on selection.index, you retrieve desired value.


          Hope it helps!





          1 person found this helpful
          • 2. Re: Set dropdown indexes?
            Pontus Uggla Level 1

            What I do now, in my big project, is that i have an object like:


            [{id: 37, value: 'Foo'}, {id: 65, value: 'Bar'}]


            I set Foo and Bar and on selection I loop through and match the values and if they match i look at the id.


            But the values needs to be unique and it takes a few extra lines of code.