I have a application in which there is one textbox and a button.I want the application to behave in such a way that when a user types some text in the text box,and after that when the user click the button,it should show whether the capslock is on or off
Asked
Active
Viewed 965 times
0
-
just detect the input is **uppercase** one(like 'a' or 'A') – tym1193 Apr 17 '12 at 05:10
-
1@tym1193: So I have to press capslock to create a single uppercase letter? I don't think so ;) (shift key). – Zeta Apr 17 '12 at 05:11
3 Answers
1
Take a look at this previous question: How do you tell if caps lock is on using JavaScript? has some great scripts/responses there for you.
-
thanks tcole,But i didnt find the solution for the button click event there too..May be i have to use the onKeyPressEvent for the textbox – user1117040 Apr 17 '12 at 05:21
0
In jQuery,
$('#example').keypress(function(e) {
var s = String.fromCharCode( e.which );
if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) {
alert('caps is on');
}
});
Avoid the mistake, like the backspace key, s.toLowerCase() !== s is needed.
You have try this code?
function isCapslock(e){
e = (e) ? e : window.event;
var charCode = false;
if (e.which) {
charCode = e.which;
} else if (e.keyCode) {
charCode = e.keyCode;
}
var shifton = false;
if (e.shiftKey) {
shifton = e.shiftKey;
} else if (e.modifiers) {
shifton = !!(e.modifiers & 4);
}
if (charCode >= 97 && charCode <= 122 && shifton) {
return true;
}
if (charCode >= 65 && charCode <= 90 && !shifton) {
return true;
}
return false;
}

sam_13
- 532
- 2
- 9
-
-
yeah sam, i did but this one works for the textbox keypress event...Anyways thank u and i think i can go on with this keypress event for the time being.. – user1117040 Apr 17 '12 at 05:39
-
It doesn't work for me, it returns true for lower case letters with no caps lock or shift key. – RobG Apr 17 '12 at 07:10
0
You could use the capslockstate jQuery plugin.
When the button is clicked you could then call $(window).capslockstate("state");
and that would tell you the state of the Caps Lock key.
Note that the state of the Caps Lock key doesn't have to be the same as when they type the text and when they click the button.

nosilleg
- 2,143
- 1
- 22
- 36