jquery - if ( keyCode == 13) allows all key values

Posted on 2014-09-01
Last Modified: 2014-09-01

I'm trying to submit a form when the enter key is pressed.  This code executes when ANY key is pressed!

function onKeyUp(e) {
  if ( e.keyCode == 13)

I've also tried "code = (e.keyCode) ? e.keyCode : e.which;" to set the value.  The keyCode value is fine.

But e.keyCode == 77 slips right through the filter!

Any ideas?
Question by:Glen Gibb
    LVL 81

    Accepted Solution

    with jQury you don't have to use : code = (e.keyCode) ? e.keyCode : e.which;

    Check here :

    The event.which property normalizes event.keyCode and event.charCode.

    Author Closing Comment

    by:Glen Gibb
    Tnx for the speedy reply!

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    To Start with ... One of the most annoying things in developing web pages is handling the 'Enter Key' for form submission. The 'Enter Key' makes form submission so easy that the user always tend to use it. The easiest and the most intuitive way …
    Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
    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)

    755 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

    19 Experts available now in Live!

    Get 1:1 Help Now