Search code examples
jquerykeyup

Checking when Enter key is pressed


I am trying to check for the event that the Enter key is executed with the value of an input containing something. Unfortunately, this doesn't work, I am running this on Google Chrome in the case that anyone is wondering.

$("#inputInput").on('keyup', function(event) {
    if (event.keyCode === 13) {
        if (document.getElementById("introInput").value != null) {
            var val = document.getElementById("introInput").value;
            alert("test");
        }
    } 
});

Anybody see what I am doing wrong?

EDIT: Screwed up by misplacing the ID with an incorrect ID, leading to nowhere, explains why there were no errors printing.


Solution

  • Hope this helps:

    $(document).on('keyup', '.#inputInput', function(event) {
      var isEnter = (event.which == 13) ? true : false;
      if (isEnter) {
        event.preventDefault();
        // Write your conditonals here
    });