This is a migrated thread and some comments may be shown as answers.

OnClientSelectedIndexChanged not firing

3 Answers 363 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 11 Apr 2008, 03:54 PM
The "OnClientSelectedIndexChanged" event does not appear to fire when the selected item is changed using the keyboard (e.g. the user tabs into the combobox then uses the arrow keys to select a new item).

Is there some other event that I can use? Or some way to make this event work?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 14 Apr 2008, 02:43 PM
Hello Scott,

This behavior is by design. Actually the item is not select through keyboard, only highlighted and its text appears in the input field.

I suggest you hook on OnClientKeyPressing event and check did you use arrow key. In this event you can execute your custom logic.

Hope this helps.

Greetings,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Scott
Top achievements
Rank 1
answered on 14 Apr 2008, 05:07 PM
Thanks for the reply.

Here is the event:

function OnClientSelectedIndexChanged(sender, args)

{

WWSHideElement(

'<%= pnlCreditCard.ClientID %>');

WWSHideElement(

'<%= pnlACH.ClientID %>');

if ( sender.get_selectedItem().get_index() == 1 )

WWSShowElement(

'<%= pnlCreditCard.ClientID %>');

if ( sender.get_selectedItem().get_index() == 2 )

WWSShowElement(

'<%= pnlACH.ClientID %>');

}

If the selected item doesn't really change when you press the up or down arrow key, then presumably "sender.get_selectedItem()" will not return the correct value.

I want to show/hide certain DIVs based on the selected payment type in the combobox. It confusing from a UI perspective to have the combobox value changed to "Credit Card" but have the page still showing ACH information. Everything worked fine with the standard combobox, but I was trying to go "all telerik" to get a more consistent look & feel. I guess I'll have to go back to the standard control if this functionality is not possible with the telerik control.

0
Rosi
Telerik team
answered on 15 Apr 2008, 11:59 AM
Hello Scott,

The OnClientSelectedIndexChanged event will fire  after you choose the item via the arrow keys and click outside of RadComboBox or hit Enter. In this case get_selectedItem will be the item which you expected.

Still you can execute your logic before hitting Enter or clicking outside in the following way:
1. Hook on OnClientKeyPressing  event.
2. Check if the arrow key is pressed.
3. Use get_highlightedItem() instead of get_selectedItem();
For example:

javascript
<script language="javascript" type="text/javascript">        
 function HandkeKeyPress(sender, eventArgs)        
 {    
 
    var index = -1;  
 
    if (eventArgs.keyCode == 38 )  
    {   
 
        item =sender.get_highlightedItem().get_index()-1;  
    }  
    if (eventArgs.keyCode == 40 )   
    {   
     item =sender.get_highlightedItem().get_index()+1;  
    }  
   if(index>-1)  
   {  
         WWSHideElement('<%= pnlCreditCard.ClientID %>');      
         WWSHideElement('<%= pnlACH.ClientID %>');      
         if ( sender.get_highlightedItem().get_index() == 1 )      
             WWSShowElement('<%= pnlCreditCard.ClientID %>');      
         if ( sender.get_highlightedItem().get_index() == 2 )      
            WWSShowElement('<%= pnlACH.ClientID %>');      
 
    }     
}   
 
</script>  
 

aspx:
<telerik:RadComboBox     
  ID="RadComboBox1"    
  runat="server"    
  OnClientKeyPressing="HandleKeyPress">     
</telerik:RadComboBox>     
 

Hope this helps.

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Scott
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Scott
Top achievements
Rank 1
Share this question
or