textarea / text

Posted on 2000-02-10
Medium Priority
Last Modified: 2013-12-24
I have a edit control that the users types in a description.  I want to limit their description to 256 characters.  I want the visible capability of a 'text area' tag that allows scrolling and multiple rows, with the 'maxlength' attribute of a 'text' tag.  To put it another way I want a 'Textarea' with a maxlength of 256 characters. Any suggestions?
Question by:wills1300

Accepted Solution

deepchanda earned 800 total points
ID: 2509541
I am not aware of any such attribute in the textarea tag, though you  can look into http://www.w3.org/MarkUp/ for the latest draft of HTML 4.0

try this

function checklen() {
   if (document.myform.test.value.length > 256) {
        alert('limit to 6 lines only');
        return false;
        return true;


<form name="myform">
<textarea name="test" cols="40" rows="5" wrap="physical" onblur="return checklen()"></textarea>

the text will wrap around by itself and 40*6 = 240 chars will be allowed with the javascript function


Expert Comment

ID: 2511437
You could also use on the onKeyPress event of the textarea, and then call a javascript function that would check the length, and not let it get any bigger.  This way, text after 256 chars wouldn't even be displayed.

:) dapperry

Expert Comment

ID: 2511474
you could check in the recieving page the length of the string and if it exceeded
the limit then inform the user...

this could be used as a
non-javascript-enabled-browser solution...


<cfif #len(nameofstring)# GT 256>
string too big!!!

Author Comment

ID: 2511626
This works very well.  I tried the other suggestion about using the onkeypress event.  I like how it only lets you type in 256 characters and no more, but it would not be invoke if someone pasted in a some text, and once you hit the 256 char, you can hit the 'backspace' button to erase because the JS message would appear.

Thanks everyone.

Expert Comment

ID: 2511776
Yeah I guess you would want to use both the onKeyPress and onBlur events.  Glad it works Ok for you.

:) dapperry

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question