Products
Services
Contact Us

Scripts: Javascript :: Forms :: Library Article #5

Developer's Section

Limit TextArea Max Characters
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (3055)
Favorites:

Limit the number of Characters an user may enter per textarea.

In this tutorial we will learn how to limit the number of characters you are allowed to enter per textarea. To do this we will use a simple javascript that will be keeping track of the number of characters. Here is an example (100 characters max):

100 characters
To achive this we do the following:

 Code Snippet 1
<script language="JavaScript">

function textCounter(field,  maxlimit) {

     if (field.value.length > maxlimit) // if too long...trim it!
     {
          field.value = field.value.substring(0, maxlimit);
     }

}

</script>


<textarea name="comments" rows="5" cols="20" 

onKeyDown="textCounter(this.form.comments,100);" 

onKeyUp="textCounter(this.form.comments,100);"></textarea>

<div align="center"><small>100 characters</small></div>


See other Scripts in Forms

 

Submit Your Scripts:


System Message:
  • Your Javascript script has been sent. Please allow 48 hours for processing.


If you would like to have your Javascripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]