Jan 18, 2012, 10:25 AM
66 Posts
topic has been resolvedResolved

Get Label Value of Combo Box in SSJS

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 2
In a combo box with a Label | Value pair, I need to get the Label value of the selected choice. I don't want a list of all the choices. I know there is .getItemLabel() and .getLabel() but these methods don't work on getComponent("comboBox1").getLabel() or getComponent('comboBox1").getItemLabel()
 
Does anyone know a way to get this label value? Thanks for any help.
Jan 19, 2012, 8:10 AM
272 Posts
Re: Get Label Value of Combo Box in SSJS
Hi,
 
you could use this function to get the selected label (id is the component id of the combo box):
 
function getSelectedLabel( id ) {
   var ComboBox = getComponent( id );
   var value = ComboBox.value;
  
   var ChildrenList:java.util.ListIterator;
   ChildrenList = ComboBox.getChildren().listIterator();
   while (ChildrenList.hasNext()) {
      var Child = ChildrenList.next();
    
      /*** process computed / multiple values ***/
      if( typeof( Child ) == 'com.ibm.xsp.component.UISelectItemsEx' ){
         var hlp = Child.getValue();
         for( var i=0; i< hlp.length; i++ ){
             if( hlp[i].getValue() == value )
             return hlp[i].getLabel() ;
         }
      }
 
      /*** process single values ***/
      if( typeof( Child ) == 'com.ibm.xsp.component.UISelectItemEx' ){

      if( Child.getItemValue() == value )
          return Child.getItemLabel();
      }
   }
}

 
Hope this helps
Sven
 
Jan 19, 2012, 8:19 AM
66 Posts
Re: Get Label Value of Combo Box in SSJS
 Thanks Sven! This is exactly what I was looking for.