onlycode.org

javascript
jquery
html
css
angularjs
node.js
ajax
html5
php
json
arrays
google-chrome
dom
regex
reactjs
ecmascript-6
javascript-events

your's history:
how to detect pressing e...

How to detect pressing Enter on keyboard using jQuery, just only code?

keyboard-events | javascript-events | jquery | javascript

edit
$(document).keypress(function(e) {
    if(e.which == 13) {
        alert('You pressed enter!');
    }
});

37
Paolo Bergantino, 11.06.2009 09:49




edit
$.fn.enterKey = function (fnc) {
    return this.each(function () {
        $(this).keypress(function (ev) {
            var keycode = (ev.keyCode ? ev.keyCode : ev.which);
            if (keycode == '13') {
                fnc.call(this, ev);
            }
        })
    })
}
$("#input").enterKey(function () {
    alert('Enter!');
})

36
Andrea, 01.04.2012 17:00




edit
$(document).keypress(function(e) {
    if(e.which == 13) {
        alert('You pressed enter!');
    }
});

35
Ian Roke, 21.06.2011 13:45




edit
$(document).keypress(function(event) {
    var keycode = event.keyCode || event.which;
    if(keycode == '13') {
        alert('You pressed a "enter" key in somewhere');    
    }
});

34
pistol-pete, 13.03.2012 21:09



edit
   $( "#start" ).on( "keydown", function(event) {
      if(event.which == 13) 
         alert("Entered!");
    });

18
SteveTurczyn, 11.10.2013 10:20




edit
$(document).ready(function(){

  $('#loginforms').keypress(function(e) {
    if (e.which == 13) {
    //e.preventDefault();
    alert('login pressed');
    }
  });

 $('#signupforms').keypress(function(e) {
    if (e.which == 13) {
      //e.preventDefault();
      alert('register');
    }
  });

});

16
Samuel Kwame Antwi, 05.01.2015 02:28




edit
$('textarea').enterKey(function() {$(this).closest('form').submit(); }, 'ctrl')
$.fn.enterKey = function (fnc, mod) {
    return this.each(function () {
        $(this).keypress(function (ev) {
            var keycode = (ev.keyCode ? ev.keyCode : ev.which);
            if ((keycode == '13' || keycode == '10') && (!mod || ev[mod + 'Key'])) {
                fnc.call(this, ev);
            }
        })
    })
}

15
joeln, 27.01.2015 04:10




edit
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test Script</title>
  <script src="/lib/js/jquery-1.7.1.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    $('.container .content input').keypress(function (event) {
      if (event.keyCode == 10 || event.keyCode == 13) {
        alert('Form Submission needs to occur using the Submit button.');
        event.preventDefault();
      }
    });
  </script>
</head>
  <body>
    <div class="container">
      <div class="header">
        <div class="FileSearch">
          <!-- Other HTML here -->
        </div>
      </div>
      <div class="content">
        <form id="testInput" action="#" method="post">
        <input type="text" name="text1" />
        <input type="text" name="text2" />
        <input type="text" name="text3" />
        <input type="submit" name="Submit" value="Submit" />
        </form>
      </div>
    </div>
  </body>
</html>

14
jp2code, 03.12.2013 01:05




edit
$(document).on("keypress", function(e){
    if(e.which == 13){
        alert("You've pressed the enter key!");
    }
});

23
jonathan klevin, 28.03.2018 15:02

Add your just only code

your name:    



If you need full text click here

Some similar links How to detect pressing Enter on keyboard using jQuery? ↓:
to call onChange event after pressing Enter key

Why does forms with single input field submit upon pressing enter key in input

Make a <br> instead of <div></div> by pressing Enter on a contenteditable

Detect virtual keyboard vs. hardware keyboard



This project is created for those who just need only code, wihout maaaaaaaaaaany words.