0

I'm developing an ASP.NET MVC 5 web page with .NET Framework 4.5.1 and C#.

I have this code:

<input type="text" class="quantity"
  name="Quantity" 
  id="Quantity"
  onkeydown='return (window.event.keyCode >= 48 && window.event.keyCode <= 57) || window.event.keyCode == 8 || window.event.keyCode == 46'
  required />

onkeydown works fine to allow only numbers, backspace and delete keys, but I can't select the input text when I click on it my the mouse.

I haven't found any relative information about this on Internet. Any idea?

VansFannel
  • 45,055
  • 107
  • 359
  • 626
  • May be you can look at [this link](http://stackoverflow.com/questions/23039374/allow-only-numbers-into-a-input-text-box/23039938#23039938) and see if it fits to your situation :) – Rohit416 Apr 27 '15 at 07:14

1 Answers1

1

Add onClick="this.select();"

<input type="text" class="quantity"
  name="Quantity" 
  id="Quantity"
  onClick="this.select();"
  onkeydown='return (window.event.keyCode >= 48 && window.event.keyCode <= 57) || window.event.keyCode == 8 || window.event.keyCode == 46'
  required />
Liam
  • 2,837
  • 23
  • 36