Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!