Saturday, February 28, 2015

How to Detect Caps Lock with JavaScript

Posted by Gnani Palepu  |  No comments


 How to Detect Caps Lock with JavaScript  
 <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>  
                 <div class="span12">  
                   <input type="password" placeholder="Password" name="Password" id="txtPassword" onkeypress="capLock(event)" title="Please enter password" required/>  
                   <div id="divMayus" style="visibility:hidden; float:left; margin-top: 0px; background-color:#3B5998; color:White;"><b>Caps Lock is on.</b></div>  
                 </div>  

3:27 AM Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top