to give warning when caps lock on

Rate It (1)

Last post 08-17-2009 3:35 AM by si.sharma. 6 replies.

Sort Posts:

  • to give warning when caps lock on

    03-01-2008, 2:36 AM
    • Member
      148 point Member
    • rcsprakash
    • Member since 02-26-2008, 12:30 PM
    • Posts 176

     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
    • Contributor
      3,551 point Contributor
    • shawpnendu
    • Member since 02-17-2008, 6:34 AM
    • Dhaka
    • Posts 622

    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.
    Shawpnendu Bikash Maloroy
    MCTS
    http://shawpnendu.blogspot.com
  • Re: to give warning when caps lock on

    03-01-2008, 4:03 AM
    Answer
    • Contributor
      3,634 point Contributor
    • akjoshi
    • Member since 05-06-2006, 9:23 AM
    • INDIA
    • Posts 614

    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
    • Member
      148 point Member
    • rcsprakash
    • Member since 02-26-2008, 12:30 PM
    • Posts 176

     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
    • Contributor
      3,634 point Contributor
    • akjoshi
    • Member since 05-06-2006, 9:23 AM
    • INDIA
    • Posts 614

    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
    • Contributor
      4,100 point Contributor
    • Scott Mitchell
    • Member since 06-15-2002, 8:41 PM
    • San Diego, CA
    • Posts 707
    • 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:
  • Re: to give warning when caps lock on

    08-17-2009, 3:35 AM
    • Member
      38 point Member
    • si.sharma
    • Member since 07-08-2009, 6:13 AM
    • Posts 28

    Hi..


           You can use this java 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';
      }




    <div id="divMayus" style="visibility:hidden">
                                     <asp:Label ID="Label1" runat="server" Text="Caps Lock is On.!" CssClass="text"></asp:Label>
                                     
                                     </div>


    <asp:TextBox ID="txtPass" CssClass="login_textbox" runat="server" TextMode="Password" onkeypress="capLock(event)"></asp:TextBox>


Page 1 of 1 (7 items)