ASP.NET C# 3.5 Web Application:- PASSWORD text box need to alert on focus if the end-user client machine keyboard CAPS LOCK ON

Hi,

    I am working with ASP.NET C# 3.5 Web Applications.

    My Requirement is:

    Let we say, the end-user / client machine keybord CAPS LOCK is in ON mode. Now the user clicks inside the PASSWORD text box in my web application (i.e.) PASSWORD textmode textbox getting focus. An alert / tooltip message need to dispaly like "CAPS KEY ON".
chrisdtrinityphysiciansAsked:
Who is Participating?
 
TonyRebaConnect With a Mentor Commented:
You need to use Javascript ,
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
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 );

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

 }
}
//  End -->
</script>

Open in new window

0
 
chrisdtrinityphysiciansAuthor Commented:
Fine solutions. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.