Introduction:
Here I will explain in jQuery how to check caps lock ON or OFF in JavaScript.Generally to 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.
Here is the function for check Caps Look is ON or OF
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');
}
}
The Full PAGE code for see the Caps lock ON or OFF.
<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>
No comments:
Post a Comment