2 Replies Latest reply on Jun 7, 2010 3:53 AM by BhaskerChari

    Issue setting selecteditem for a dropdownlist

    dasun1981

      I have a form with a dropdown box which I need to change the selected item in it. This is a update form which values returned from an http service and I'm trying to set the selected item using the following code. But it is returning an error. Really appriciate If someone can tell me how I can set the selected item.

       

      cmbSuppliers.selectedItem = event.result.component.batches.batch.supplierid.toString();

       

      I also tried the following as well, but still getting the

       

      cmbSuppliers.selectedItem.id =  event.result.component.batches.batch.supplierid.toString();

       

      the combo box arraylist contain id field and the supplier name.

       

      I'm getting the following error.

       

      TypeError: Error #1010: A term is undefined and has no properties.

        • 1. Re: Issue setting selecteditem for a dropdownlist
          BhaskerChari Level 4

          Hi dasun,

           

          Try to use the selectedIndex property of the combobox to set the selectedItem in combobox. It is always a good approach to use the selectedIndex property to set the selecteditem.

           

          Try using the below code:

           

          var strSupplierId:String = event.result.component.batches.batch.supplierid.toString();
          for(var intLoop:int=0;intLoop<ddlDP.length;intLoop++)
          {
               var supplierID:String = String(ddlDP.getItemAt(intLoop).supplierid);
                          
               if(strSupplierId == supplierID)
               {
                    cmbSuppliers.selectedIndex = intLoop;
                    break;
               }
          }

           

          In the above code ddlDP is the cmbSuppliers dataprovider(which is an arraycollection).

           


          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

          1 person found this helpful
          • 2. Re: Issue setting selecteditem for a dropdownlist
            BhaskerChari Level 4

            ???

            1 person found this helpful