Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Detect Caps Lock On or Off in JavaScript

Nov 12, 2014
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.


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


Enter Text:


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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

7 comments :

Anonymous said...

Thanks you sir. I have a suggestion i.e, it would be really great if you also explain the code. please add comments.

Anonymous said...

HOW WE KNOW THE PARAMETERS OF AN EVENT checkcapslockon(event)

جنید عطاری said...

10+

Anonymous said...

aa

Anonymous said...

Message should be displayed while entering only first letter, not on each letter entry.

Anonymous said...

Good article

Anonymous said...

Not Working(While caps lock on and press any number alert says caps off)

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.