Quick Search:
 
 JavaScript: Limit Text Area Characters Jump to:  
Category: >> JavaScript >> Limit Text Area Characters  

<< lastnext >>

Snippet Name: Limit Text Area Characters

Description: Limit the number of characters that can be entered into a text area. Works with any number of text areas on the same page.

Comment: (none)

Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: February 27th, 2009

<script type="text/javascript">
	FUNCTION textCounter(textarea, counterID, maxLen) {
		cnt = document.getElementById(counterID);
		IF (textarea.value.length > maxLen){
			textarea.value = textarea.value.substring(0,maxLen);
		}
		cnt.innerHTML = maxLen - textarea.value.length;
	}
</script>
 
<textarea name="mytext" id="mytext" style="width:99%; height:100px;" value="" 
onkeyup="textCounter(this,'count_display',255);" 
onBlur="textCounter(this,'count_display',255);"
></textarea><br>
<span style="position: relative; left: 15;">
<table cellpadding="0" cellspacing="0" border="0" style="font-size:10px;"><tr><td>
Chars left:&nbsp;</td><td width="30" bgcolor="#ffffbb"><span id="count_display">255</span>
</td><td>&nbsp;(255 max)</td></tr></table>
</span>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org