Home > other >  I want to stop user to input in a specific moment by JavaScript
I want to stop user to input in a specific moment by JavaScript

Time:10-14

I have a textarea where I have created a limitations of 0/150 word the 0 number increases 1, 2, 3 like that and when it goes to 150/150 I want that textarea not to take more inputs now I have tried to disable the textarea it works but user cant undo their text so actually I want that it stop taking more inputs plus user can undo their changes not disabling the textarea

if(document.getElementById("maximum_length").innerText==150){
  document.getElementById("pro_desc").disabled = true;
}
else if(document.getElementById("maximum_length").innerText<=150){
  let current = document.getElementById("maximum_length").innerText
  document.getElementById("maximum_length").innerText = Number(current)   1;
}

CodePudding user response:

Try to use maxlength attribute:

<textarea maxlength="150">
  • Related