Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: Disable number input but the up and down arrow should work

Tags:

html

angular

I have this input type number but I need to disable user input on the box. The up and down arrow should increase or decrease the number displayed.

<td data-th="Quantity">
    <input type="number" min="1" max="99" class="form-control text-center" value="{{cartItem.quantity}}" formControlName="quantity" #itemQuantity>
</td>

enter image description here

How can I make it work?

like image 590
Mix Austria Avatar asked Dec 14 '25 21:12

Mix Austria


2 Answers

You can disable all related user keyboard/mouse events like as onKeyPress="return false", onCut="return false", onPaste="return false" as following code:

.form-control {
  padding: 8px; 
  border: 1px solid #ccc; border-radius: 4px;
}

.text-center { text-align: center; }
<input type="number" min="1" max="99" class="form-control text-center" value="{{cartItem.quantity}}" formControlName="quantity" #itemQuantity
onkeypress="return false" 
ondragStart="return false" onselectstart="return false"       
oncut="return false" oncopy="return false" onpaste="return false" 
ondrag="return false" ondrop="return false" 
autocomplete="off"
>
like image 69
S.Serpooshan Avatar answered Dec 16 '25 10:12

S.Serpooshan


<td data-th="Quantity">
    <input type="number" min="1" max="99" class="form-control text-center" value=" 
   {{cartItem.quantity}}" formControlName="quantity" (keypress)="eventHandler($event)"  
    #itemQuantity>
</td>

eventHandler(event){
   event.preventDefault();
}
like image 43
kaushal shah Avatar answered Dec 16 '25 11:12

kaushal shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!