Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrows not working on input type="number"

Tags:

html

css

I used a simple html

<input type="number">

It is showing a text box with up and down arrows but the arrows are not working. The value can be incremented/decremented with arrows on keyboard and mouse scroll, but when I click on any of the arrows, it seems that the down arrow is clicked and the value in the box remains the same. Please suggest what should I do!

like image 499
Surya Purohit Avatar asked Dec 15 '15 06:12

Surya Purohit


People also ask

How do you input a type number?

The <input type="number"> defines a field for entering a number. Use the following attributes to specify restrictions: max - specifies the maximum value allowed. min - specifies the minimum value allowed.


2 Answers

Well I'm surprised by this but it looks like a bug, at least in Chrome. (Edge doesn't show the arrows at all and Firefox behaves correctly.)

The mousemove event listener (on the element or the document) breaks the INPUT TYPE="number" if an e.preventDefault() is present:

<input type="number" value="1"/>

$(function() {
    $(document).on('mousemove', function (e) {
        e.preventDefault();
    });
});

See https://jsfiddle.net/MCAU/Lpojfrm2/

Can anyone confirm this?

like image 94
MSC Avatar answered Oct 15 '22 17:10

MSC


You can try this:

HTML

<div id="incdec">
<input type="text" value="0" />
<img src="up_arrow.jpeg" id="up" />
<img src="down_arrow.jpeg" id="down" />
</div>

JQuery

$(document).ready(function(){
$("#up").on('click',function(){
    $("#incdec input").val(parseInt($("#incdec input").val())+1);
});

$("#down").on('click',function(){
    $("#incdec input").val(parseInt($("#incdec input").val())-1);
});

});
like image 24
Jibin Balachandran Avatar answered Oct 15 '22 17:10

Jibin Balachandran