Last active
December 30, 2015 09:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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