Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Caps lock check with Javascript in Firefox

Posted on 2007-03-27
1
Medium Priority
?
4,250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
jhshen earned 375 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

705 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