3

In the HTML input text, using the onKeyUp method I am able to catch the click event on enter button when input type="text" .

But the same event is not able to fire if the input type="number".

HTML

<input id="inputLocation" type="text" class="inputBarCode" style="text-transform: uppercase" placeholder: placeholder/>

JS

 $('#inputLocation').keyup(function (e) {
     if (e.which === 13) {
         $('#inputLocation').blur();
         //self.executeLocationLookup();
         alert("Event ", e.which);
     }
 });

Can you please let me know how to get the click event(13) of the enter button if input type is numeric keyboard

Please Refer the attached image

TylerH
  • 20,799
  • 66
  • 75
  • 101
new_coder
  • 67
  • 10

2 Answers2

0

Use event.target.value property or $(this).val()

$('#inputLocation').keyup(function (e) {
  if (e.which === 13 && isNumber(e.target.value)) {
     $('#inputLocation').blur();
     //self.executeLocationLookup();
     alert("Event ", e.which);
  }
});  

function isNumber(n) {
   return !isNaN(parseFloat(n)) && isFinite(n);
}
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
0

It is better to actually listen to the submit event, which is triggered when the enter key is pressed.

Use the following markup:

<form>
    <input id="inputLocation" type="text" class="inputBarCode" style="text-transform: uppercase" placeholder: placeholder/>
</form>

and you can use submit() to listen for the submit event.

$('form').submit(function (e) {
    // prevent the page from auto-navigating on form submit
    e.preventDefault();

    // do something
});
Daniel Apt
  • 2,468
  • 1
  • 21
  • 34