post icon

Javascript detect Caps Lock key active or disactive when input password string into textbox

Come rilevare lo stato del tasto Caps Lock (maiuscolo) da un campo di input textbox. 

<html> <head> <title>CapsLock</title> <script language="Javascript"> 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'; } </script> </head> <body> <FORM> <SPAN><input type="password" name="txtPassword" onkeypress="capLock(event)" /> <SPAN><div id="divMayus" style="visibility:hidden">Caps Lock is on.</div> </FORM> <script language="Javascript"> capLock(window.event); </script> </body> </html>

Download DetectCapsLock.zip (502,00 bytes)

1 febbraio 2009 @ 11:23

No comments yet.

Leave a comment

Leave a Reply

Are you human? Time limit is exhausted. Please reload CAPTCHA.