www.webdeveloper.com
Results 1 to 6 of 6

Thread: Disabling Submit form on Enter key press

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    48

    Disabling Submit form on Enter key press

    Hi guys,

    Wondering if there's a better way than what I'm doing to disable that when a user presses Enter, the form is submitted.

    I'm catching the enter key onkeydown events. And it works fine on input boxes but I noticed that if a user selects something on a drop down menu and presses the enter key, the form is also submitted. As far as I know drop downs don't have an onkeypress event.

    Is there a way to cancel form submission when the Enter key is pressed? Or any ideas how to catch this event on a drop down?

    Thanks

  2. #2
    Join Date
    Feb 2010
    Posts
    34
    <form onsubmit="return false"/>

  3. #3
    Join Date
    Mar 2010
    Posts
    48
    Ty

  4. #4
    Join Date
    Jan 2013
    Posts
    1

    Thumbs up Disable Form Submit on Enter Key Press

    Check this post on how to disable form submit/postback on Enter key press. Works on all browsers.

  5. #5
    Join Date
    Jan 2013
    Posts
    3
    Code:
    function stopRKey(evt) {
      var evt = (evt) ? evt : ((event) ? event : null);
      var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
      if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
    }
    
    document.onkeypress = stopRKey;

  6. #6
    Join Date
    Jan 2013
    Posts
    3
    Sorry, forgot to add the source of above script.

    Source

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles