Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  35] [ 6]  / answers: 1 / hits: 51054  / 12 Years ago, thu, april 5, 2012, 12:00:00

Here is an example:





$(function() {
$('#test').change(function() {
$('#length').html($('#test').val().length)
})
})

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<textarea id=test maxlength=10></textarea>
length = <span id=length>0</span>





Fill textarea with lines (one character at one line) until browser allows.
When you finish, leave textarea, and js code will calculate characters too.



So in my case I could enter only 7 characters (including whitespaces) before chrome stopped me. Although value of maxlength attribute is 10:



imgur


More From » html

 Answers
66

Your carriage returns are considered 2 characters each when it comes to maxlength.



1rn
1rn
1rn
1


But it seems that the javascript only could one of the rn (I am not sure which one) which only adds up to 7.


[#86404] Wednesday, April 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taylert

Total Points: 627
Total Questions: 91
Total Answers: 108

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
taylert questions
;