Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
How can I make "numbers" input uneditable in a matter of typing?

I know how to make numbers input completely read only. However, how do I make it typing locked? Since I can type in it endless numbers even though the max value is 10 (and it works but only when using this up and down thing). If there's any code needed let me know, although I don't think so

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use Javascript to check what the number's value is every time it changes, and if it's higher (or lower) than what you've specified, reset the value to the maximum or minium:

let number = document.getElementById("number");

let max = 10;
let min = 0;

number.addEventListener('input', () => {  

  if (number.value > max) {
    number.value = max;
  }
  
  if (number.value < min) {
    number.value = min;
  }

  
});
<input type="number" id="number" step="1" max="10" min="0">

about 4 years ago · Juan Pablo Isaza Denunciar

0

Still use the number type since that will do at least some of the checking for you but catch the user's input and if the number would become too big go back to the previous value (i.e. ignore the most recent typed digit just as you would an a-z character).

let limitedInputs = document.querySelectorAll("input.limitedNumber");
let prevValue = 0;

limitedInputs.forEach(input => {
  input.addEventListener('input', () => {

    if (input.value > input.max) {
      input.value = prevValue;
    } else if (input.value < input.min) {
      input.value = input.min;
    } else {
      prevValue = input.value;
    }

  });
});
<input type="number" max="10" min="0" class="limitedNumber">

This snippet just sets the min value if the user's typed value goes too low but you may want to make the behavior different depending on the minimum value.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda