Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire a method when click an Enter key

Tags:

angularjs

<form novalidate name="frm1" autocomplete="off">

   //UI elements                               

   <div class="col-sm-3 col-sm-offset-6">
      <button ng-click="MyFunc()">Next Step</button>
   </div>
 </form>

Can you tell me how to fire MyFunc() method when click the enter key.On the above form where there is no submit button. Thanks in advance.

like image 585
Sampath Avatar asked May 04 '15 07:05

Sampath


People also ask

How do you trigger a function on Enter?

To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.

How do you call a function when Enter is pressed?

You can execute a function by pressing the enter key in a field using the key event in JavaScript. If the user presses the button use the keydown to get know its enter button or not. If it enters the key then call the JavaScript function.

Which tag acts as Enter key on the keyboard?

<kbd>: The Keyboard Input element.


1 Answers

Try this:

<input ng-keyup="$event.keyCode == 13 ? MyFunc() : null" >

At form level you can use this:

<form ng-submit="myFunc()" ...>
like image 152
Rahul Tripathi Avatar answered Sep 19 '22 20:09

Rahul Tripathi