Saturday, 10 September 2016

Enter Key Disable in Asp.net using Simple javascript

<script language="javascript" type="text/javascript">
function restrickEnterKeyForAddress(e)
        {
            var key;
                if(window.event)
                {
                    key = window.event.keyCode;
                }
                else
                {
                    //store the key code (Key number) of the pressed key
                    key = e.which;     
                }
                //if key 13 is pressed (the enter key)
                if(key == 13)
                {
                    //do nothing
                    return false;
                    //otherwise
                }
                else
                {
                    //continue as normal (allow the key press for keys other than "enter")
                    return true;
                }
        }
</script>

<asp:TextBox ID="txt" runat="server" onKeyPress="return restrickEnterKeyForAddress(event)">
</asp:TextBox>

No comments:

Post a Comment