Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:28:10+00:00 2026-06-15T19:28:10+00:00

My following code for checking whether Capslock is on or not works fine on

  • 0

My following code for checking whether Capslock is on or not works fine on “onkeypress” event.

But i want it for “onfocus” event.
i tried replacing “onkeypress” with “onfocus” for the control,but it doesnt work for me.

Any help? (either in javascript or Jquery)

 <script type="text/javascript" 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>

<input type="text" name="txtuname" />
<input type="password" name="txtPassword" onkeypress="capLock(event)" />
<div id="divMayus" style="visibility:hidden">Caps Lock is on.</div> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:28:11+00:00Added an answer on June 15, 2026 at 7:28 pm

    There is a jQuery plugin called capslockstate which will keep track of the state of the caps lock key, allowing you to use that information as and when needed.

    It will monitor the state for the entire page, and then you can retrieve the state when the desired element gains focus.

    It’s also based on watching key presses, but not limited to lower ASCII characters and handles situations like the Caps Lock key itself being pressed.

    Your situation would become something like:

    <script src="{path-to}/jquery-capslockstate.js"></script>
    <script>
        $(document).ready(function() {
            $(window).capslockstate();
    
            $(window).bind("capsOn", function(event) {
                if ($("#txtPassword:focus").length > 0) {
                    document.getElementById('divMayus').style.visibility = 'visible';
                }
            });
            $(window).bind("capsOff capsUnknown", function(event) {
                document.getElementById('divMayus').style.visibility = 'hidden';
            });
            $("#txtPassword").bind("focusout", function(event) {
                document.getElementById('divMayus').style.visibility = 'hidden';
            });
            $("#txtPassword").bind("focusin", function(event) {
                if ($(window).capslockstate("state") === true) {
                    document.getElementById('divMayus').style.visibility = 'visible';
                }
            });
        });
    </script>
    
    <input type="text" name="txtuname" />
    <input type="password" name="txtPassword" id="txtPassword" />
    <div id="divMayus" style="visibility:hidden">Caps Lock is on.</div>
    

    Note that I’ve only jQueryified the essential bits, more could still be done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was checking whether a file exists or not but i get error with
I have following code for checking whether there is duplicate in an array. The
The following code is an alternative to using navigator.onLine - by checking whether the
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
Following code gets executed whenever I want to persist any entity. Things seems to
Following code is a pretty simple and complete JQuery Dialog. Everything works. Problem is
I'm using the following code for checking if a key exists in a Map
The following piece of code works with regular SQL and SMO. I'm trying to
I have following code that checks whether date is valid. http://jsfiddle.net/uzSU6/36/ If there is
Following code produces a nested array as a result for keys containing three items:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.