10 Replies Latest reply on Sep 17, 2010 2:45 PM by jmw107

    drop drown list values (CS3 JS)

    jmw107 Level 1

      Hi -- I am stumped on something that seems to me should be simple:


      I am using script UI to build a drop down list.



      //I set my drop down list values

      var mySizes = ['10', '12', '14', '16', '18', '20', '22', '24', '26', '28', '30', '32', '34', '36', '38', '40', '42'];

      //I create a dialog, panel etc., then my dropdownlist

      dlg.msgPnl.titleEt = dlg.msgPnl.add('dropdownlist', [50,20,120,40], mySizes);

      //I set what the default is in the dropdown list

      dlg.msgPnl.titleEt.items[7].selected = true;

      //When the user clicks OK in the dialog, I want to grab the value of what they chose in the drop down list.

      //My first try gave me a value of the index. i.e., if I chose '10', I get a value of 0 because that is the index of the value.

      myValue = dlg.msgPnl.titleEt.selection.index;

      //Obviously, I do not want that; I want the value. But at least I know my script is working -- just giving me the index instead of the value. So I tried a couple of different ways but neither returned the value:

      myValue = dlg.msgPnl.titleEt.selection;

      myValue = dlg.msgPnl.titleEt.selected;


      Can anyone tell me what I need to do to get the value?


      thanks in advance

        • 1. Re: drop drown list values (CS3 JS)
          jmw107 Level 1

          Nevermind -- I figured it out:


          var myValue = dlg.msgPnl.titleEt.selection.text;


          Simple! Sorry for wasting a post.

          • 2. Re: drop drown list values (CS3 JS)
            [Jongware] Most Valuable Participant

            Actually, since you already have an array, you could have used it again to retrieve the nth value:


            myValue = mySizes[dlg.msgPnl.titleEt.selection];


            (On the other hand, there is a different sort of drop down list with only suggestions, where you can select an item or type in anything you want. Kind of like InDesign's own point size list. In that case, you should always retrieve 'what the user entered', because it just may be something that's not in your list. I'm racking my brain right now -- does ScriptUI support this or not?)


            Sorry for wasting a post.


            Your 25th post? Don't worry, you have enough ones left.

            • 3. Re: drop drown list values (CS3 JS)
              Steven.. Level 3

              From the OMV




              Data Type: ListItem

              ScriptUI Classes

              The currently selected list item.

              Setting this value causes the selected item to be highlighted and to be scrolled into view if necessary. If no items are selected, the value is null. Set to null to deselect all items.You can set the value using the index of an item, rather than an object reference. If set to an index value that is out of range, the operation is ignored. When set with an index value, the property still returns an object reference.





              Since a ListItem is returned, the way to get the text would be with the ListItem's text property.


              However since index can be used in place of object, it returns an index by default...

              • 4. Re: drop drown list values (CS3 JS)
                jmw107 Level 1

                Thanks ... one wrinkle I have come across:


                In my previous post, I was using script ui to set the value of a point size. Both your method or selection.text seems to work fine for that.


                But I can't seem to do the same for fillTint.


                Hardcoding it in my script works: myText.fillTint = 50. But using the value from the dropdown list does not: myText.fillTint = dlg.msgPnl.titleEt2.selection.text or myValue = myTint[dlg.msgPnl.titleEt2.selection] (myTint being my array for the dropdownlist).


                What's odd is that using these methods does return the correct value -- I tested it with an alert box.

                Is the problem that by using selection.text, it is giving me the number as a text string and fillTint wants only a number? I do know that if you try myText.fillTint = 50 it works, but myText.fillTint = '50' wil not. But either will work with pointSize.



                I tried my array two ways but got the same non-results:

                var myTint = ['40', '45', '50', '55']; and var myTint = [40, 45, 50, 55];


                I have looked at the script UI classes in the OMV, but can't seem to find a solution.


                Any ideas?



                • 5. Re: drop drown list values (CS3 JS)
                  [Jongware] Most Valuable Participant

                  Perhaps fillTint only expects 'real' numbers, and isn't smart enough to recognize a number-in-string format. It's likely because of this: pointSize can accept a number, which usually is measured in points, but you can also set it to any 'measurement' string, such as "5 mm".


                  Try with forcing your selection.text forced into a number, like this:


                  myText.fillTint = Number(dlg.msgPnl.titleEt2.selection.text);
                  • 6. Re: drop drown list values (CS3 JS)
                    jmw107 Level 1

                    Nope ... didn't work. Is there anyway to specify its a number in the dropdownlist array or the

                    dropdownlist controls?


                    I also tried 'edittext' instead of 'dropdownlist' but as you might guess, that did not work either.

                    • 7. Re: drop drown list values (CS3 JS)
                      [Jongware] Most Valuable Participant

                      The override didn't work? That cannot be right. Did it do nothing, or didya get an error?


                      Try this, to find out if at least the dialog part works:


                      theSetFillTint = Number(dlg.msgPnl.titleEt2.selection.text);
                      alert (theSetFillTint+" is of type "+theSetFillTint.constructor.name);


                      -- it should report this


                      "50 is of type Number"


                      and it's the type I'm interested in. If it is "Number" then assigning this to fillTint fails for some reason.

                      • 8. Re: drop drown list values (CS3 JS)
                        jmw107 Level 1

                        Yes, it returned that.

                        • 9. Re: drop drown list values (CS3 JS)
                          jmw107 Level 1

                          sorry, forgot to add --  I did not get an error.

                          • 10. Re: drop drown list values (CS3 JS)
                            jmw107 Level 1

                            My apologies -- I must have left something out my first try -- I got it to work.


                            Thanks for your help with this.