JQuery - Prevent enter key from submitting Form

Posted on 2011-10-11
Last Modified: 2012-05-12
I have a form.  Looking for a JQuery ONLY way of preventing the form from submitting when the ENTER key is hit.

Please - not looking for basic Javascript.
Question by:carsRST
    LVL 81

    Accepted Solution

    $(document).ready(function() {
    		$(document).keypress(function(e) {
    			if(e.keyCode == 13) e.preventDefault();

    Open in new window

    LVL 16

    Author Closing Comment

    Thanks, Professor leakim971!

    You need secret service protection.  You're a huge asset, man.
    LVL 81

    Expert Comment

    thanks for the points, have a nice week
    see you soon

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
    Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question ( on how to make a page show some balloons animate up a page…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now