4
My goal in a previous post was to put a maximum and minimum value in a text field, a user solved it almost perfectly. Let’s use as an example at most the number 37
:
function checa(e){
const mi = +e.min;
const ma = +e.max;
const va = e.value;
if(va < mi){
e.value = mi;
}else if(va > ma){
e.value = ma;
}
}
<input oninput="checa(this)" value="1" type="number" min="1" max="37">
However, if the maximum number is for example 10
, it will not be able to delete the number 1 to be able to type for example a 7
. But the minimum number has to be 1, someone would know how to extend this solution?
Follow the link from the old post: Limit number on an input
How ... I didn’t understand?
– novic