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

How do I set MAXLENGTH in TEXTAREA? 1

Status
Not open for further replies.

MENON

Programmer
Jul 23, 2001
28
US
Hi All,

I need to have a text input for 500 chars. I thought of using TEXTAREA but it doesn't have the MAXLENGTH attribute available with "INPUT type=text"

Does anyone have any suggestions.

Thanks,
Rakesh
 
I don't know about javascript, but you can do this in vb script:

<script language=vbscript>
sub TextAreaName_onkeyup()
if len(myForm.TextAreaName.Value) > 500 then
myform.TextAreaName.Value = myform.textareaname.value,500)
End If
</script> Tazzmann
 
In Javascript, you could do it this way:

Code:
<script language=javascript>
  function CheckLength(txt, MaxChars) {
    var X = txt.value
    if (X.length > MaxChars) {
      alert ('You have entered too many characters for this field.  The maximum # of characters is' + MaxChars);
      txt.focus();
      txt.value = txt.value.substring(0,500);
    }
  }
</script>

<TEXTAREA Name='Whatever' Rows=6 Cols=45 onKeyUp=&quot;javascript:CheckLength(this, 500);&quot;></TEXTAREA>
 
Thanks Niv3K and TazzMann.

I should have thought about that.

Regards,
Rakesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top