SITERAW

HTML textarea maxlength

Author Message
Posey # Posted two hours ago
Posey

Hello everyone,

I'm trying to apply a maxlength property to my <textarea> element but the character count (checked in real time through Javascript) doesn't match with what is being entered.

For debugging purposes I added rows and columns to my textarea but it doesn't really tell me where my problem is located or why the field is behaving that way.

Here is my code.

<textarea name="text" rows="9" cols="55" maxlength="495"></textarea>
I have my 9 lines and 55 columns, except that in the last line I cannot enter more than 39 characters out of 55, 476 characters out of 495 in total.

Do you have any idea why it's behaving that way.

Ads
Celeri # Posted two hours ago
Celeri

Careful, chariot returns (CRLF) are included in the maxlength.

Posey # Posted one hour ago
Posey

Aaaaah, I knew it was a stupid error!

I blame lack of sleep :)

Out of curiosity I ran into another question during the debugging... if I change the limit to maxlength="495", so that I can enter my 495 characters (8 carriage returns for the first 8 lines), I get warned that I can enter only 495.

However, if I exceed 495 characters, a warning appears which indicates that I can only enter 511 characters...

How does one avoid this contradiction?

Celeri # Posted one hour ago
Celeri

Your approach doesn't seem good. Display how many empty characters are left, the CRLF will whatever happens be part of the total.

<textarea name="text" rows="9" cols="55" maxlength="495"onkeyup= "console.log('Still: ', this.maxLength - this.value.length)"></textarea>

Kegon # Posted 7 minutes ago
Kegon

That's some tard-level shit code op.

Post a reply

Please be kind and courteous in your replies. Don't roast others for no reason.