Can anyone help me to use the enter key to execute this program?

46 views Asked by At

I have created a small program that pulls from the YouTube API which allows you to search for a random video for whatever title you enter when prompted. I have it so everything is working except, I would like to be able to hit the enter key on the keyboard to run the search. I would assume that the fix is as simple as an onKeyDown event, but I have tried to implement it a few ways and it seems to break every time. I'm not sure if it is because the way I am calling my onClickListener or what. Any help would be appreciated.

1

There are 1 answers

5
Leeish On BEST ANSWER
$('#searchterm').keydown(function(e){
  if(e.keyCode == 13){
    search();
  }
});