Disable the "Enter" as Submit behavior? RRS feed

  • Question

  • User1638786547 posted
    With a form with multiple submit buttons, the behavior is extremely annoying.

    Does anyone know of any good way of getting rid of it?
    Friday, June 30, 2006 6:43 PM

All replies

  • User-587754273 posted
    That's easy. To disable the Enter key, you can use javascript:
    First, add onkeydown in the body tag:
    <body  onclick="javascript:EnterKeyFilter();" >

    And then, add the function:
    function EnterKeyFilter()
    {  if (window.event.keyCode == 13)
        {   event.returnValue=false;
            event.cancel = true;

    That's it.

    Friday, June 30, 2006 10:33 PM
  • User-587754273 posted
    sorry, I made a mistake.
    the body tag should like this:
    <body onkeydown="javascript:EnterKeyFilter();">

    Not onclick.
    Friday, June 30, 2006 10:34 PM
  • User445179017 posted

    If you were using ASP.Net buttons, then you can set the UseSubmitBehavior property to false.

    Saturday, July 1, 2006 6:30 AM
  • User1065039236 posted

     This worked nicely:   if (eventArgs.KeyCode == 13) return false;


     <asp:Button ID="btnOpen" runat="server" Text="Open" OnClientClick=" if (eventArgs.KeyCode == 13) return false;"/>


    If a confimation is desired then use:

    <asp:Button ID="btnOpen" runat="server" Text="Open" OnClientClick=" if (eventArgs.KeyCode == 13) return false; return confirm('All unsaved data will be lost.  Continue Open?');"/>

    Thursday, May 14, 2009 9:08 AM
  • User1623646749 posted

    This is so simple,

    Try below on <body> tag

    <body onkeydown="return (event.keyCode!=13)" onunload="">

    Tuesday, July 16, 2019 2:37 PM