javascript – limit the number of characters in a textarea 1 comment


<script language="javascript" type="text/javascript">
function limitText(fieldLimit, countLimit, limitNum) {
if (fieldLimit.value.length > limitNum) {
fieldLimit.value = fieldLimit.value.substring(0, limitNum);
} else {
countLimit.value = limitNum - fieldLimit.value.length;
}
}
</script>
<form name="form_name">
<textarea name="sometext" onKeyDown="limitText(this.form.sometext,this.form.counter,100);"
onKeyUp="limitText(this.form.sometext,this.form.counter,100);">
</textarea><br />
(Maximum characters: 100)<br />
You have <input readonly type="text" name="counter" size="3" value="100"> characters left.
</form>

thanks to : http://www.g31zone.com/?p=240

Share on Facebook




About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools


One thought on “javascript – limit the number of characters in a textarea