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

[Solved] OnClientKeyPressing event returning code for UpperCase only

1 Answer 179 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jack Helm
Top achievements
Rank 1
Jack Helm asked on 12 Feb 2010, 03:45 PM
I am trying to capture the key pressed in a RadComboBox and determine if it is upper or lower case. I used the following code just to see what I was getting back:
function ddAgents_KeyPress(sender, eventArgs) {  
    var TextIn = eventArgs.get_domEvent().keyCode;  
    var stop=1;  
I have this in there so I can put a stop on Stop=1 and mouse over and look at the value of TextIn. When I do this and run it, if I type a letter in, I will use the letter "g" as an example, the value of keyCode is the ascii value for the uppercase letter regardless of which is typed. So if I type in a "g", or a "G" either way the keyCode value is 71. what am I doing wrong? I have removed all styles though I have the Filter="StartsWith". Not sure if that could have anything to do with it or not, but if it does, I have no idea why. Any thoughts on why this is happening?

Here is my code where I setup the control just in case it helps:
<telerik:RadComboBox ID="ddAgents" Runat="server" Width="100px" AutoPostBack="true" OnSelectedIndexChanged="ddAgents_SelectedIndexChanged" Filter="StartsWith" OnClientKeyPressing="ddAgents_KeyPress">  
 




1 Answer, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 18 Feb 2010, 11:21 AM
Hello Jack Helm,

Thanks for your question.

When you press a key the keyCode returns the code of the key and doesn't make difference between uppercase letters and small letters. If you want to make difference between uppercase and standard letters, an additional logic is needed. Here's an example:

function capLock(e) {
            kc = e.keyCode ? e.keyCode : e.which;
            sk = e.shiftKey ? e.shiftKey : ((kc == 16) ? true : false);
            if (((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
            {
                alert(kc);
            }
            else
                alert(kc);
        }

You can see the full example in the attached .zip file.

Please let me know if this was helpful.

All the best,
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ComboBox
Asked by
Jack Helm
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Share this question
or