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

Prevent user from typing particular characters example does not work

2 Answers 131 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Emran
Top achievements
Rank 1
Emran asked on 15 Feb 2009, 10:40 PM
I'm trying to disallow the up and down arrow key press on the text area of the combo (to ensure users do not accidentally select a different item) and used the following example provided in:
http://www.telerik.com/help/aspnet-ajax/combo-prevent-typing-particular-characters.html.

i am using firebug to step through the problem, the event fires however, the keypress is not disallowed.
I reverted back to example and noticed the example does not work too.

Please advise or post a working example.

<script type="text/javascript">
 function pageLoad() {
        var combo = $find("<%= RadComboBox1.ClientID %>");
        var input = combo.get_inputDomElement();
        input.onkeydown = onKeyDownHandler;
    }

    function onKeyDownHandler(e) {
        if (!e)
            e = window.event;

        var code = e.keyCode;
        //do not allow any of these chars to be entered: !@#$%^&*()
        //if (e.shiftKey && code >= 48 && code  <= 57){
        if (code >= 39 && code <= 40) {
            e.returnValue = false;
            if (e.preventDefault) {
                e.preventDefault();
            }
        }
    }
</script>  

<telerik:RadComboBox runat="server" ID="RadComboBox1" Height="400px"
            Width="100%" AllowCustomText="True"
            ShowMoreResultsBox="True"
            EnableVirtualScrolling="True"
            EnableLoadOnDemand="True"
            HighlightTemplatedItems="true"
            EnableItemCaching ="true"
            onitemsrequested="RadComboBox1_ItemsRequested"  
            onclientselectedindexchanged= "AllowSelectionChanged"
            onclientselectedindexchanging = "AllowSelectionChange"
            OnClientItemsRequesting="OnClientItemsRequesting"
            OnClientTextChange = "ValidateChange" Font-Size="X-Small"
  ShowDropDownOnTextboxClick="False">







2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Feb 2009, 11:49 AM
Hi Emran,

Try the following JavaScript and check whether its working fine.

JavaScript:
function onKeyDownHandler(e)  
{  
   if (!e)  
       e = window.event;         
   var code = e.keyCode;    
   //do not allow any of these chars to be entered: !@#$%^&*()  
    if (code == 38 || code == 40)  
    {   
       e.cancel =true;  
       try 
       {  
            e.returnValue = false;  
            e.cancelBubble = true;  
            if(document.all){ //IE  
                e.keyCode = 0;  
            }  
            else//NS  
                e.preventDefault();  
                e.stopPropagation();  
            }  
        }catch(ex)  
        {  
        }        
    }          
}  

Thanks,
Princy.
0
Roman
Top achievements
Rank 1
answered on 28 Oct 2010, 12:25 PM
Hello,
The example provided here: http://www.telerik.com/help/aspnet-ajax/combo-prevent-typing-particular-characters.html, works on a qwerty keyboard; how about French-input keyboards (azerty)?
Is there a way to allow both input types?
Thanks
Tags
ComboBox
Asked by
Emran
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Roman
Top achievements
Rank 1
Share this question
or