How to handle the `onKeyPress` event in ReactJS?

How can I make the onKeyPress event work in ReactJS? It should alert when enter (keyCode=13) is pressed. var Test = React.createClass({ add: function(event){ if(event.keyCode == 13){ alert(‘Adding….’); } }, render: function(){ return( <div> <input type=”text” id=”one” onKeyPress={this.add} /> </div> ); } }); React.render(<Test />, document.body); 12 Answers 12

Submit form on pressing Enter with AngularJS

In this particular case, what options do I have to make these inputs call a function when I press Enter? Html: <form> <input type=”text” ng-model=”name” <!– Press ENTER and call myFunc –> /> <br /> <input type=”text” ng-model=”email” <!– Press ENTER and call myFunc –> /> </form> // Controller // .controller(‘mycontroller’, [‘$scope’,function($scope) { $scope.name=””; $scope.email=””; … Read more

jQuery Event Keypress: Which key was pressed?

With jQuery, how do I find out which key was pressed when I bind to the keypress event? $(‘#searchbox input’).bind(‘keypress’, function(e) {}); I want to trigger a submit when ENTER is pressed. [Update] Even though I found the (or better: one) answer myself, there seems to be some room for variation 😉 Is there a … Read more