Javascript – enable Enter key in your keyboard

Bind a function which is called functionWasCalled to the Enter key of your keyboard :

HTML :

<html>
  <body>
    <input id="idOfInput" type="text" />
  </body>
</html>

Javascript :

$('#idOfInput').die('keypress').live('keypress', 
    { instance : self }, function (e) {
         if ( e.keyCode == 13 ){ self.functionWasCalled(e);}
 });
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s