Website Designing

This is a simple script for extending your textarea with a maxlength attribute
Textarea Maxlength script
HTML clipboard
This is a simple but effective script for extending your textarea with a maxlength attribute, so the user's input cannot exceed a certain number of characters. Works with any number of textareas on the page.
 
Step 1: Add the below script to the <HEAD> section of your page:

<script type="text/javascript">

/***********************************************
* Textarea Maxlength- © Jooria Refresh Your Site (www.jooria.com)
* This notice must stay intact for legal use.
* Visit http://www.jooria.com
***********************************************/

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

</script>

Step 2: Inside any textarea you wish to add a "maxlength" attribute to, simply do the following:

<textarea maxlength="40" onkeyup="return ismaxlength(this)"></textarea>

The part in red is what you should add, with "40" obviously being the maximum number of characters accepted by this textarea.

Enjoy!

 
in: » Website Designing | Posted on Apr 10th, 2009 | views 5,841
you can see also [tutorials]:
  1. Textarea Maxlength script
About the author
i'm moustafa from egypt i love doing one thing 'web programming & designing', This year I've got 19 years old and i'm in the english College of management (in Business Administration part soon)