-1

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;
}
Arnob Roy
  • 13
  • 3
  • Check if this helps you out [Textarea Characters Limiting](https://stackoverflow.com/a/5607015/15405352) – Anil Parshi Oct 14 '21 at 06:25
  • 2
    Does this answer your question? [How to prevent input to a textarea after a certain character count is reached?](https://stackoverflow.com/questions/30088102/how-to-prevent-input-to-a-textarea-after-a-certain-character-count-is-reached) – CBroe Oct 14 '21 at 06:26
  • 1
    textarea tags support a `maxlength` attribute. You can use that. https://jsfiddle.net/1yrkob0x/ – volt Oct 14 '21 at 06:26

1 Answers1

1

Try to use maxlength attribute:

<textarea maxlength="150">
Ali Vojdanian
  • 2,067
  • 2
  • 31
  • 47