Skip to content

Instantly share code, notes, and snippets.

@jasongaylord
Last active December 30, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongaylord/7810665 to your computer and use it in GitHub Desktop.
Save jasongaylord/7810665 to your computer and use it in GitHub Desktop.
A jQuery version of the capslock.html GIST found at https://gist.github.com/jasongaylord/7797819.
<html>
<head>
<title>Test Caps Lock</title>
</head>
<body>
<div id="capsLockWarning" style="font-weight: bold; color: maroon; margin: 0 0 10px 0; display: none;">Caps Lock is on.</div>
Username: <input type="text" id="username" /><br/>
Password: <input type="password" id="password" />
</body>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script language="javascript">
function isCapsLockOn(e) {
var keyCode = e.keyCode ? e.keyCode : e.which;
var shiftKey = e.shiftKey ? e.shiftKey : ((keyCode == 16) ? true : false);
return (((keyCode >= 65 && keyCode <= 90) && !shiftKey) || ((keyCode >= 97 && keyCode <= 122) && shiftKey))
}
$(document).ready(function() {
$(":password").keypress(function(e) {
if (isCapsLockOn(e))
$("#capsLockWarning").show();
else
$("#capsLockWarning").hide();
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment