SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Resource

Adding a MaxLength Attribute to TextArea

Categories...
Client User Group
Internet Explorer
Language
JavaScript
Product
IE5
Task
Components, Form Enhancement
Technology
IE5 Behaviors, Intrinsic Controls

Sponsored Links
Developer's Paradise : Inside Technique :
Adding a MaxLength Attribute to TextArea
Submission by SiteExperts Staff

Go to the resource:
Adding a MaxLength Attribute to TextArea

Add to Assistant

Short Description
An IE5 behavior (htc) that adds support for a MaxLength attribute to the TextArea element.

Long Description
The standard HTML input box has a MaxLength property that limits the length of the user's input. Matthew extends this behavior to the TextArea element by creating an IE5 behavior.

Author
Matthew Frank
Date/ Version
10/4/1999
Submission URL
http://www.SiteExperts.com/ie5/htc/ts08/page1.asp
Submission Date
Oct 4,1999
Last Update
Oct 4,1999
 

Discussion and Rate this Resource
Overall Rating: 3.8

Joshie76 on Jun 25, 2002 at 3:26:02 AMNo Rating

Smart. I wasn't aware of the defaultValue property before, very handy! Thanks.

chipple on Jun 24, 2002 at 9:45:39 PMNo Rating
Oops I meant "Joshie76's code". :)
chipple on Jun 24, 2002 at 9:41:41 PMNo Rating

Here's my take at enabling resetting on textareas using this behaviour. This is a modification of 's code.

<html>
<head>
    <title>
        Textarea reset test...
    </title>
    <style type="text/css">
  textarea {behavior: url(maxlength.htc)}
 </style>
<script type="text/javascript"><!--
function fResetTextarea (oForm) {
  for (var i = 0; i < oForm.length; i++) {
    if (oForm.elements[i].type == "textarea")
      oForm.elements[i].value = oForm.elements[i].defaultValue;
  }
}
//--></script>
</head>
   <body>        
      <form onReset="fResetTextarea(this);">
       <textarea maxlength="10"></textarea><br/>
  <input type="text"/><br/>
         <input type="reset" />
      </form>
   </body>
</html>

Good luck!,

Joshie76 on Jun 24, 2002 at 1:37:32 AMNo Rating

Thanks again Mack. I thought that problem would turn out to be a browser bug, shame. Thanks for trying though.

Josh

mack on Jun 21, 2002 at 11:06:15 AMNo Rating

I've installed IE6 now.  After trying in vain to make my HTC work with the reset button, i tried another experiement.  This time, I created an empty file called "test.htc" and assigned it as the behavior rather than maxlength.htc.  The reset button still doesn't work.  My guess is that IE6 has a bug in it regarding behaviors.  Or it just doesn't support them in the same way as IE5 did.

mack on Jun 21, 2002 at 8:13:44 AMNo Rating

Let me see if I can get an IE6 machine here.  I tried your test page in IE5 and it worked as expected. 

Joshie76 on Jun 21, 2002 at 1:45:25 AMNo Rating

I've set up a test at http://www.hrmsoftware.com/test/behaviors/textarea.htm.

 

Joshie76 on Jun 21, 2002 at 1:40:36 AMNo Rating

Thanks Mack.

I just tried your test HTML in the same directory and it still didn't clear. I'm using IE6 on W2K and the same happens on IE6 with XP Pro. Just tested it on IE5.5 on W2K and it doesn't work there either. The maxlength is working fine, the textarea just won't reset...

help!

mack on Jun 20, 2002 at 12:50:33 PMRating: 5

Behaviors do not work in Netscape or Mozilla.  They are restricted to Internet Explorer 5+ at the moment.  Maybe someday, the W3C will incorporate behaviors as a standard.

Here is a simple example of how the htc file is incorporated:

 

<html>
<head>
<title>test</title>
<style type="text/css">
textarea {behavior: url(maxlength.htc)}
</style>
</head>
<body>
<form>
<textarea maxlength="30"></textarea>
<input type="reset" />
</form>
</body>
</html>

I have this test.htm file in the same directory as the .htc file. The reset button clears the textarea as expected.  I can't say what your problem could be unless you actually have a default value in the textarea when you expect to have none.

Joshie76 on Jun 20, 2002 at 1:56:49 AMNo Rating

I've run into some trouble with this script. It seems when you reset your forms the textareas no longer reset!

Any ideas? Help!

Ravi Kumar on May 30, 2002 at 3:54:17 AMRating: 1
any one can give me how ti use it in HTML coding
mini75 on Nov 8, 2001 at 10:22:53 AMNo Rating
I am not sure if I have understood correctly how to use these functions. What and where am I suppose this code. Can you please help.
amul_luma on Jul 2, 2001 at 12:03:06 AMNo Rating

Is this maxlength for textarea works in netscape

poojarajdev on Feb 12, 2001 at 2:34:12 AMRating: 1

Hi!

This code is not working fine with me.I dont know what is the problem. I downloaded the file "htc" and added it in css as specified in the article.

What could be the problem please tell, somebody?

Jovan on Jan 20, 2001 at 4:21:47 PMRating: 4
I have tried this script it works ok, but I have problems with the pictures on the bottom of my page www.doktor.co.yu/formular.html Sometimes one of two pictures is not displayed (after refresh). On other pages everything is ok, so I think that there is problem in this script or IE?
mack on Jan 25, 2000 at 8:45:27 AMNo Rating

I performed the test you mentioned and was not able to paste more than 55 chars.  Are there any other changes you made which might affect the test?  I'd like to fix any problems since people may be using this on production sites.

Basically, I pulled the page and HTC off of this site and altered the maxlength attribute to "55".  It seems to work fine as far as I can tell.

jparrish on Jan 7, 2000 at 8:48:17 AMRating: 4

Good, but one minor problem....change the maxlength to 55, then cut-n-paste the following 0123456789. It will actually let you paste 6 times or a total of 60 characters.

mack on Oct 7, 1999 at 4:57:17 PMNo Rating
I cannot re-create this error.  Is there any more information you can give me?  Was it on the sample within the article or on your own page?
pbienick on Oct 6, 1999 at 5:23:03 AMRating: 3

Nice but blows up when I try to paste text. I get the following error:

line: 26
Error: 'window.clipboardData.getData(...)' is not an object

I am using IE 5, full version: 5.00.2314.1003CO

Yachoo on Oct 6, 1999 at 2:01:37 AMRating: 4
asdfasdfasdfdasfasdfasdfasdfasdfasdfdassdafasdfasfasdfdasfadsfasdf

Most Recent Ratings/ Comments


To rate and comment on a resource, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password

Copyright © 1997-2008 InsideDHTML.com, LLC. All rights reserved.