pradeep kumar

pradeep kumar

  • NA
  • 94
  • 66.1k

Caps lock event not firing.

Dec 27 2012 1:33 AM
<script type="text/javascript">
function checkCapsLock(e) {
            debugger;
            if (!e)
                e = window.event;
            var fKeyCode = 0;
            var myShiftKey = true;
            var msg = 'You are pressing shift key or attempting to type in caps';
            var myMsg = 'Caps Lock is On.';
            if (document.all) {
                fKeyCode = e.keyCode;
                myShiftKey = e.shiftKey;
            }
            else if (document.layers) {
                fKeyCode = e.which;
                myShiftKey = (fKeyCode == 16) ? true : false;
            }
            else if (document.getElementById) {
                fKeyCode = e.which;
                myShiftKey = (fKeyCode == 16) ? true : false;

            }
            if ((fKeyCode >= 65 && fKeyCode <= 90) && !myShiftKey) {
                alert(myMsg);
            }

        }

</script>





<asp:Login ID="Login1" runat="server" class="loginForm" OnAuthenticate="Login1_Authenticate">
<tr>
                                        <td align="right">
                                            <asp:Label ID="Label1" runat="server"></asp:Label>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="Password" runat="server" TextMode="Password" Width="150px" onClick="return checkCapsLock(e)"
                                                Height="5px"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                                ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="log">*</asp:RequiredFieldValidator>
                                        </td>
                                    </tr>

</asp:login>


Im checking Caps lock on here i tried with onkeypress,onkeydown,onkeyup.., Java script is not firing if i use on click it showing error 'e' is undefined..

I really cant find where im missing...,

thanks in advance.

Answers (8)