Below is an input number form and with JavaScript, I have added some line of codes with the minimum number that can be written is 1 and the maximum number to be written would be 50. And when someone would try to type any number less than 1 and greater than 50 it would automatically replace it with number 1 or 50 but I'm not having success achieving this and I need your help.
document.getElementById('info1').addEventListener("input", function () {
let num = +this.value, max = 50, min = 1;
if (num > max || num < min) {
return false;
}
})
<input type="number" id="info1" size="4">