I don’t think you can achieve this, JavaScript offers no direct way to check the state of the Caps Lock,
Only thing you can do is to use a script which checks the letters pressed and compares them with the SHIFT key state, but this will work only when an alphabet key is pressed and not in case when any numeric, function
keys are pressed.
When you ask a question, remember to click "mark as answered" when you get a reply which answers your question; this ensures the right forum member gets credit for being helpful (and makes search more relevant too).
Marked as answer by rcsprakash on Mar 03, 2008 04:07 AM
No, unless a key is pressed you can't detect whether Caps is on or off. and i dont think there is any way to simulate a key press using javascript.
When you ask a question, remember to click "mark as answered" when you get a reply which answers your question; this ensures the right forum member gets credit for being helpful (and makes search more relevant too).
rcsprakash
Member
163 Points
191 Posts
to give warning when caps lock on
Mar 01, 2008 06:36 AM|LINK
hi guys,
in my website i have login page. if the user focus the username txtxbox ,i want show a warning msg.(like a popup) when caps lock is on.
how to check the caps lock is on or not in a web.
Senior Software Engineer
iLink Multitech Solution Pvt. Ltd
Chennai,TN,India.
shawpnendu
Contributor
4275 Points
749 Posts
Re: to give warning when caps lock on
Mar 01, 2008 07:49 AM|LINK
Add the javascript mehod given below:
MCTS
http://shawpnendu.blogspot.com
akjoshi
Contributor
3636 Points
615 Posts
Re: to give warning when caps lock on
Mar 01, 2008 08:03 AM|LINK
I don’t think you can achieve this, JavaScript offers no direct way to check the state of the Caps Lock,
Only thing you can do is to use a script which checks the letters pressed and compares them with the SHIFT key state, but this will work only when an alphabet key is pressed and not in case when any numeric, function keys are pressed.
A script like this one -
http://javascript.internet.com/forms/check-cap-locks.html
rcsprakash
Member
163 Points
191 Posts
Re: to give warning when caps lock on
Mar 03, 2008 04:09 AM|LINK
HI ALL,
thanks to ur reply.
what i need the is, warning to be show to the user, when the page is load or just user focus the txtxbox. is it possible
Senior Software Engineer
iLink Multitech Solution Pvt. Ltd
Chennai,TN,India.
akjoshi
Contributor
3636 Points
615 Posts
Re: to give warning when caps lock on
Mar 03, 2008 07:44 AM|LINK
No, unless a key is pressed you can't detect whether Caps is on or off. and i dont think there is any way to simulate a key press using javascript.
Scott Mitche...
Contributor
4114 Points
712 Posts
ASPInsiders
MVP
Re: to give warning when caps lock on
May 14, 2008 03:41 AM|LINK
Check out this article:
Warning the User When Caps Lock is On
http://aspnet.4guysfromrolla.com/articles/051408-1.aspx
In it I provide a compiled server control that you can add to your page, set a few properties, and you're off and running.
Happy Programming!
"caps lock"
-- Scott Mitchell
-- mitchell@4guysfromrolla.com
-- http://scottonwriting.net/sowblog/
-- http://www.4GuysFromRolla.com/ScottMitchell.shtml
SI.Sharma
Member
686 Points
199 Posts
Re: to give warning when caps lock on
Aug 17, 2009 07:35 AM|LINK
Hi..
You can use this java script..
function capLock(e){
kc = e.keyCode?e.keyCode:e.which;
sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
document.getElementById('divMayus').style.visibility = 'visible';
else
document.getElementById('divMayus').style.visibility = 'hidden';
}
<div id="divMayus" style="visibility:hidden">
<asp:Label ID="Label1" runat="server" Text="Caps Lock is On.!" CssClass="text"></asp:Label>
</div>
<asp:TextBox ID="txtPass" CssClass="login_textbox" runat="server" TextMode="Password" onkeypress="capLock(event)"></asp:TextBox>