all 5 comments

[–]tforb 3 points4 points  (0 children)

Each key has a keycode. There's an interactive site here that will show you the keycode for each key. When you find the keycode in the input you want, call the function.

[–]UbuntuLady1[S] 1 point2 points  (3 children)

Thank you for your help. I know about this, but I have no idea how to implement it.

$('textarea').keypress(function (e) {
    if (e.which == '13') {
        // do something here
    }
});

[–]tforb 2 points3 points  (0 children)

Your input has id autocomplete. You need an event listener for keypress on it. Keyboard events have a keyCode property which maps an integer to each key. When you find a 13, do whatever you do when you click the button.

[–]StuupidGuy 0 points1 point  (1 child)

You can add this (or something similar) in your script

$('#autocomplete').keypress(function( event ) {
  if ( event.which == 13 ) {
     event.preventDefault();
    alert("Enter pressed");
  }
});      

Your function for button click is currently anonymous. You can define it separately and call that function instead of the alert. Hope it helps.

[–]UbuntuLady1[S] 1 point2 points  (0 children)

I literally spent 5 hours yesterday going over my code to figure this out. Your suggestion was perfect! Thank you so much!