5 Replies Latest reply on Jul 8, 2009 7:04 AM by mr. modus

    Get comboBox value on a button click.

    mr. modus Level 1

      I'm sure this is easy as pie but I'm a noob and am having a heck of a time.


      I have a datagrid populated from an xml doc. For each row in the datagrid I have a comboBox with ID=Quantity and a button which will run a function for checkout. The user chooses their quantity from the comboBox and hits the buy button. What I'm trying to do is read the chosen quantity from the comboBox and then change the url accordingly. However I have no idea how to get the value from the comboBox since it's not the comboBox supplying the event.


      Here's my datagrid:













      <mx:DataGrid id="invGrid" dataProvider="{invXML}">






           <mx:DataGridColumn headerText="Quantity" itemRenderer="renderers.rend_Quantity"/>



           <mx:DataGridColumn dataField="ActualPrice" headerText="Our Price"/>



           <mx:DataGridColumn itemRenderer="renderers.rend_BuyButton"/>








      Here's the guts of my Quantity renderer:




      id="Quantity" dataProvider="{data.ValidSplits.int}"/>


      Here's the guts of my Buy button renderer:















      xmlns:mx="http://www.adobe.com/2006/mxml" id="Buy" label="BUY" click="parentDocument.buyItem()"/>


      This is my function.


      // function to go to checkout


      public function buyItem():void{


           var s:String = "view=cart;id=" + invGrid.selectedItem.ID + ";quantity=" + Quantity.selectedItem;

           browserManager.setFragment(s); // set the url fragment










      I get an error when using Quantity.selectedItem, which I expected since there are multiple comboBoxes with Quantity as the ID. I've tried

      Quantity[invGrid.selectedIndex].selectedItem but get an error as well.


      How do I target this comboBox? Any help is greatly appreciated.






        • 1. Re: Get comboBox value on a button click.
          leybniz Level 4

          your Quantity ComboBox is external component, that's why you cannot access it via given id='Quantity'


          Fast solution for you is to modify your combobox to set chosen value directly to selected grid item

          <mx:ComboBox dataProvider="{data.ValidSplits.int}" change="data.quantity = this.selectedItem" />


          inside byItem access this value as



          If you feel this message answers your question or helps, please mark it respectively

          1 person found this helpful
          • 2. Re: Get comboBox value on a button click.
            mr. modus Level 1

            Thanks for your response.


            The only problem is that the user doesn't need to necessarily change the comboBox to choose the item. As an example the comboBox may have the following values: 2,4,6,10. The behavior desired is that the highest value is selected by default. Some comboBoxes may only have "2" as the option. So if the user doesn't change the default value the var won't have been set.


            Is there another way without relying on the comboBox to provide an event?

            • 3. Re: Get comboBox value on a button click.
              leybniz Level 4

              Actually it's easy to preset default values automatically:


              after you have items loaded to the grid, loop something like this:

              for each (var item:* in invGrid.dataProvider)

                   item.quantity = fetchHighestValueOutOf(item.ValidSplits.int);


              Even more better solution is to do this loop on backend

              • 4. Re: Get comboBox value on a button click.
                mr. modus Level 1

                I'm afraid that still doesn't help me though. I need to read the specific set comboBox value of the row that the button that's clicked is in. For instance I may have 100 rows all with comboBoxes. Some might be defaulted to "1", some "2" some "5", some "10" etc. If the button on row 18 is clicked I need to get the value of the comboBox on row 18. Does that make sense?

                • 5. Re: Get comboBox value on a button click.
                  mr. modus Level 1

                  I'm still really in a bind here. Could one of you good folks please please help me out. I'm a noob and have some trouble getting my head around OO sometimes. I just need a way to get the comboBox selected value in the same row as the button that's clicked.


                  I appreciate your time.