Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Size of Textarea field

Status
Not open for further replies.

Kush

Programmer
Sep 20, 2000
24
0
0
US
How can I limit the number of characters that a user can enter in a textarea? For example, in case of a <input TYPE=&quot;text&quot;>, one can use MAXLENGTH attribute to limit the number of charaters a user can enter. But there is no such option for <TEXTAREA>.

Any help will be greatly appreciated.

Thanks.
 
According to the &quot;Index of HTML 4.0 Elements&quot;, there isn't an attribute to limit the input size of a textarea. You'll have to do it programatically. I guess you could check each keypress and count them. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks tsdragon. I thought as much.
 
What you can do is use the len() function and check the length that way as part of your form verification/submission process. I believe you can do this client side with javascript or server side in the asp code itself. I don't have a code sample but it would be something like:

Code:
if txaStuff.len()>100 then
....
end if

Unfortunately I don't remember if this is the correct syntax. Crystal
crystalized_s@yahoo.com

--------------------------------------------------

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
Crystal,
Thanks for your response. I am using ColdFusion for my application and to restrict the number of characters to 100, I am using the Len() and the Mid() function. The syntax is like this:
<CFSET s = Trim(#Form.Name#)>
<CFIF Len(s) GT 100>
<CFSET s = #Mid(s, 1, 100)#>
</CFIF>

Kush
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top