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

How do you specify max length for a textarea?

Status
Not open for further replies.

LucyL

Technical User
Feb 20, 2002
113
US
How do you specify max length for a textarea?
Help Appreciated.
 
I don't think you can specify the max length in HTML. You could use a text box for that, though. You could probably use a javascript to validate the box and check for character length before submitting.
 
Try this, it was posted here more then a year ago by Vituz:

<html><head><title>textarea length</title>
<SCRIPT language=&quot;JavaScript&quot;>
<!--
function count_change(form){
Msg = form.txtarea.value;
Msglen= Msg.length;
//maximum length
MaxLen=20;
if (Msglen > MaxLen ){
form.txtarea.value=Msg.substring(0,MaxLen);
alert(MaxLen+&quot; symbols allowed only!!&quot;)
} form.txtarea.focus(); }
//-->
</SCRIPT>
</head>
<BODY>
<FORM name=&quot;form1&quot; METHOD=&quot;POST&quot; >
<TEXTAREA cols=50 name=txtarea rows=5 MAXLENGTH=20 WRAP=virtual onChange=&quot;count_change(document.forms[0])&quot; onkeypress=&quot;count_change(document.forms[0])&quot;></TEXTAREA><br>
<input type=button value=&quot;show length&quot; onclick=&quot;alert(this.form.txtarea.value.length)&quot;>
</form>
</body>
</html>

Hope this helps,
Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top