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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enforce Maxlength on Textarea

Status
Not open for further replies.

florida1987

IS-IT--Management
Dec 9, 2007
26
For a textarea how do I limit the number of characters in the box to 500?

For input text I can set to maxlength and limit the entry in the input: <INPUT TYPE=TEXT NAME="myInfo" MAXLENGTH=500>
For textarea I assume I need to create a validation or something to fetch the length of the field and stop the entry after 500 characters. Please advise how this can be done.

Code:
if(form.myInfo.value.length() > 500)
{
   //how would I stop the length in the textarea here?
}
 
You can either do a count of characters in the "value" on "keypress", or you could check when the form is submitted (client- and server-side validation). I've used both in the past, and both work well.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top