2 Replies Latest reply on Mar 13, 2008 6:16 AM by Gregory Lafrance

    Combo Box vs HTML Select

    saunchad
      I am used to an HTML select tag where in the option tag you can assign a value (like an ID) but display some text (like a name).

      How can I do that same thing with a Combo box?
        • 1. Re: Combo Box vs HTML Select
          SujitG Level 2
          You can use list of Objects instead of list of Strings as the data provider of the ComboBox component. When you are accessing/using the value call comboBox.selectedItem.data. Please find the sample below.


          <mx:ComboBox id="comboBox">
          <mx:ArrayCollection>
          <mx:Object label="AL" data="Montgomery"/>
          <mx:Object label="AK" data="Juneau"/>
          <mx:Object label="AR" data="Little Rock"/>
          </mx:ArrayCollection>
          </mx:ComboBox>

          Hope this helps.
          • 2. Re: Combo Box vs HTML Select
            Gregory Lafrance Level 6
            You can also use the "value" property to get the currently selected value:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
            <mx:Panel x="10" y="10" width="350" height="200" title="Rate Customer Service">
            <mx:ComboBox id="cbxRating" x="20" y="20" width="100">
            <mx:dataProvider>
            <mx:Array>
            <mx:String>Satisfied</mx:String>
            <mx:String>Neutral</mx:String>
            <mx:String>Dissatisfied</mx:String>
            </mx:Array>
            </mx:dataProvider>
            </mx:ComboBox>
            <mx:Button x="140" y="20" label="Send"/>
            <mx:Label x="20" y="120" text="{cbxRating.value}"/>
            </mx:Panel>
            </mx:Application>

            Also, it is always best, where appropriate, to populate the combo box from an external xml file or data service call, to make your architecture more extensible.