Solved

Caps lock check with Javascript in Firefox

Posted on 2007-03-27
1
4,212 Views
Last Modified: 2012-05-05
I found the following JavaScript code which is exactly what I was looking for in another question.  However the only problem is the shift key check does not work in Firefox, does anyone know what code needs to be added to get this to work in Firefox.

<HTML>
<HEAD>
<TITLE>Check Caps Lock</TITLE>
<LINK REL="stylesheet" HREF="jgw.css" TYPE="text/css">
<SCRIPT LANGUAGE=JavaScript>
<!--

/*
// ///////////////////////////
// checkCapsLock v1.0
//
// If a user enters his password in a Web-based form with Caps Lock
// accidentally on, he can become frustrated because his password is not
// being accepted... and he may assume the application is the source of the
// problem.
//
// This JavaScript function will let the user know his Caps Lock is on and
// about the potential for error.
// ///////////////////////////
*/

function checkCapsLock( e ) {

      var myKeyCode=0;
      var myShiftKey=false;
      var myMsg='Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

      // Internet Explorer 4+

      if ( document.all ) {
            myKeyCode=e.keyCode;
            myShiftKey=e.shiftKey;

      // Netscape 4
      } else if ( document.layers ) {
            myKeyCode=e.which;
            myShiftKey=( myKeyCode == 16 ) ? true : false;

      // Netscape 6
      } else if ( document.getElementById ) {
            myKeyCode=e.which;
            myShiftKey=( myKeyCode == 16 ) ? true : false;

      }

      // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
      if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
            alert( myMsg );
            return false;

      // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
      } else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
            alert( myMsg );
            return false;
      }

}
// -->
</SCRIPT>
</HEAD>

<BODY>

<H1>Check Caps Lock</H1>

Do you have problems with users who continually have problems logging in
because they inadvertently have their Caps Lock on?  Well, now you can let
your users know the problem may be due to Caps Lock.

<FORM name=pwform>
<STRONG>Password:</STRONG>
<INPUT TYPE="Text" NAME="Password" SIZE=16 MAXLENGTH=16 onKeyPress="return checkCapsLock(event)">
<P>
<INPUT TYPE="Reset">
</FORM>


</BODY>

</HTML>
0
Comment
Question by:interstate
1 Comment
 
LVL 2

Accepted Solution

by:
jhshen earned 125 total points
ID: 18800598
You may refer to this website for the details of keystrokes detection for different browser.
http://www.quirksmode.org/js/keys.html
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php survey script 4 59
WPF issue with Trigger 2 69
Need sample Angular apps for study 4 36
Need a good Angular tutorial 5 35
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now