Page view counter

to give warning when caps lock on

Rate It (1)

Last post 05-13-2008 11:41 PM by Scott Mitchell. 5 replies.

Sort Posts:

  • to give warning when caps lock on

    03-01-2008, 2:36 AM
    • Loading...
    • rcsprakash
    • Joined on 02-26-2008, 12:30 PM
    • Posts 169
    • Points 146

     hi guys,

     

    in my website i have login page. if the user focus the username txtxbox ,i want show a warning msg.(like a popup) when caps lock is on.

    how to check the caps lock is on or not in a web.

    - Suria Prakash,
    Software Developer
    D'zine Garage Pvt. Ltd
    Chennai,TN,India.
  • Re: to give warning when caps lock on

    03-01-2008, 3:49 AM
    Answer
    • Loading...
    • shawpnendu
    • Joined on 02-17-2008, 6:34 AM
    • Posts 587
    • Points 3,368

    Add the javascript mehod given below:

    <script>
    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>
    TO call the script from ur control:
    <SPAN><input type="password" name="txtPassword" onkeypress="capLock(event)" />
    <SPAN><div id="divMayus" style="visibility:hidden">Caps Lock is on.</div>
     
    Modify the script by alert.
     
    Hope its helpful for u.
    DON't FORGET TO MARK AS ANSWER if its helpful for u.
    MCP Shawpnendu Bikash Maloroy
    http://shawpnendu.blogspot.com
  • Re: to give warning when caps lock on

    03-01-2008, 4:03 AM
    Answer
    • Loading...
    • akjoshi
    • Joined on 05-06-2006, 1:23 PM
    • INDIA
    • Posts 614
    • Points 3,629

    I don’t think you can achieve this, JavaScript offers no direct way to check the state of the Caps Lock,

    Only thing you can do is to use a script which checks the letters pressed and compares them with the SHIFT key state, but this will work only when an alphabet key is pressed and not in case when any numeric, function keys are pressed.

    A script like this one -

    http://javascript.internet.com/forms/check-cap-locks.html

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question; this ensures the right forum member gets credit for being helpful (and makes search more relevant too).
  • Re: to give warning when caps lock on

    03-03-2008, 12:09 AM
    • Loading...
    • rcsprakash
    • Joined on 02-26-2008, 12:30 PM
    • Posts 169
    • Points 146

     HI ALL,

    thanks to ur reply.

    what i need the is, warning to be show to the user, when the page is load or just user focus the txtxbox. is it possible

    - Suria Prakash,
    Software Developer
    D'zine Garage Pvt. Ltd
    Chennai,TN,India.
  • Re: to give warning when caps lock on

    03-03-2008, 3:44 AM
    • Loading...
    • akjoshi
    • Joined on 05-06-2006, 1:23 PM
    • INDIA
    • Posts 614
    • Points 3,629

    No, unless a key is pressed you can't detect whether Caps is on or off. and i dont think there is any way to simulate a key press using javascript.

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question; this ensures the right forum member gets credit for being helpful (and makes search more relevant too).
  • Re: to give warning when caps lock on

    05-13-2008, 11:41 PM
    • Loading...
    • Scott Mitchell
    • Joined on 06-15-2002, 4:41 PM
    • San Diego, CA
    • Posts 707
    • Points 4,100
    • ASPInsiders
      TrustedFriends-MVPs

    Check out this article:

    Warning the User When Caps Lock is On
    http://aspnet.4guysfromrolla.com/articles/051408-1.aspx

    In it I provide a compiled server control that you can add to your page, set a few properties, and you're off and running.

    Happy Programming! 

    Happy Programming!


    -- Scott Mitchell
    -- mitchell@4guysfromrolla.com
    -- http://scottonwriting.net/sowblog/
    -- http://www.4GuysFromRolla.com/ScottMitchell.shtml
    Filed under:
Page 1 of 1 (6 items)