Prevent user from typing particular characters example does not work

3 posts, 0 answers
  1. Emran
    Emran avatar
    4 posts
    Member since:
    Nov 2008

    Posted 15 Feb 2009 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Feb 2009 Link to this post

    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.
  3. Roman
    Roman avatar
    1 posts
    Member since:
    Oct 2010

    Posted 28 Oct 2010 Link to this post

    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
Back to Top