shlomof
asked on
limit number of characters in <textarea>
Is there any way to limit number of character in <textarea> same as "maxlength" property in <input type="text" maxlength="50">? I need something to work exectly same way - no warnings and no alerts. Just prevent from additing more characters.
Here's a script that does limit the number of characters you can enter into a text box. It's a little longer than dij8's, but you can see a working demo of it too.
http://www.shiningstar.net/articles/articles/javascript/dynamictextareacounter.asp?ID=AW
http://www.shiningstar.net/articles/articles/javascript/dynamictextareacounter.asp?ID=AW
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ClassyLinks,
This script is doing exactly the same as dij8's. Thanks anyway.
This script is doing exactly the same as dij8's. Thanks anyway.
ASKER
thanks dij8!!!
Glad to have helped. Thanks for the A.
And Classylinks, thanks for the subtle tip on fixing the last character problem I had. :-)
And Classylinks, thanks for the subtle tip on fixing the last character problem I had. :-)
Oh...is that what I did??? ;-) LOL
Ciao for now!
Ciao for now!
<script language="javascript" type="text/javascript">
function settalength(field) {
field.value = field.value.substr(0,50)
}
</script>
<textarea onkeypress="settalength(th
Doing it this way will have the last character change as a new key is pressed. And note that hitting return is good for two characters (carriage return, line feed).