Introduction:
Here I will explain in jQuery how to detect caps lock on or off in JavaScript. Generally to detect or check caps lock on or off in page load it’s not possible we can analyze key code only in key press using jQuery or JavaScript.
Description:
In previous articles I explained jQuery check if checkbox is checked or not, jQuery change opacity of image on mouseover, jQuery change image on mouseover, jQuery dropdown with images, jQuery show alert message while leaving from website, jQuery Countdown timer script example and many articles relating to jQuery, JavaScript and asp.net. Now I will explain how to detect caps lock on or off in jQuery or JavaScript.
In previous articles I explained jQuery check if checkbox is checked or not, jQuery change opacity of image on mouseover, jQuery change image on mouseover, jQuery dropdown with images, jQuery show alert message while leaving from website, jQuery Countdown timer script example and many articles relating to jQuery, JavaScript and asp.net. Now I will explain how to detect caps lock on or off in jQuery or JavaScript.
If you want to detect or check caps loc on or off jQuery
or JavaScript
we need to write the code like as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Check Capsloc on or not in Javascript</title>
<script type="text/javascript">
function checkcapslockon(e) {
var charKeyCode = e.keyCode ? e.keyCode : e.which;
var shiftKey = e.shiftKey ? e.shiftKey : ((charKeyCode == 16)
? true : false);
if (((charKeyCode >= 65 && charKeyCode <= 90)
&& !shiftKey) || ((charKeyCode >= 97 && charKeyCode <=
122) && shiftKey)) {
alert('Caps Loc
On');
}
else {
alert('Caps Loc
Off');
}
}
</script>
</head>
<body>
<form id="form1"
runat="server">
<div>
<b>Enter Text:</b><input type="text" id="txtname" onkeypress="checkcapslockon(event)"/>
</div>
</form>
</body>
</html>
|
Live
Demo
To
check live demo try to enter text or press Caps Lock button and check status
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
7 comments :
Thanks you sir. I have a suggestion i.e, it would be really great if you also explain the code. please add comments.
HOW WE KNOW THE PARAMETERS OF AN EVENT checkcapslockon(event)
10+
aa
Message should be displayed while entering only first letter, not on each letter entry.
Good article
Not Working(While caps lock on and press any number alert says caps off)
Note: Only a member of this blog may post a comment.