What I have:
I have a textarea with a dynamic width and height. I'm using p5.dom.js to create DOM elements with width and height according to the windows width and height.
What I want:
I want to restrict the characters in the textarea so it can't be bigger than the size of the textarea. When the character get to this point, the user shouldn't be able to insert more characters.
Problems:
textarea {
resize: none;
overflow: hidden;
}
Even when I remove the resize and the scroll bar, it doesn't stop it from going down. When the user types one more letter this happens.
I know that I can use maxlength
or rows and cols, but because the textarea have a dynamic width and height, I'm trying to find a solution where you don't use this attributes.
Solutions:
- The only solution the I thought of this making a event to check when the scroll bar goes down and remove 1 character until the scroll bar goes back to the top. How to check that?
- Removing the ability of the scroll and not just hiding the scroll bar. I look in a lot of places but i could only find questions that hide the scroll bar.
If there's no way to do that in CSS, jQuery would be a good way.
Edit 1:
It's ok if some users have lower character limit than others