Hi frineds ,
This is a simple script but we are using sometimes. To count the characters in a textarea using javascript explained with demo.
Javascript code
In the header section of the page:
<!-- Start the Script -->
<script language=javascript>
//Edit the counter/limiter value as your wish
var count = "125"; //Example: var count = "143";
function limiter(){
var tex = document.myform.comment.value;
var len = tex.length;
if(len > count){
tex = tex.substring(0,count);
document.myform.comment.value =tex;
return false;
}
document.myform.limit.value = count-len;
}
</script>
<!-- end of Script -->
<script language=javascript>
//Edit the counter/limiter value as your wish
var count = "125"; //Example: var count = "143";
function limiter(){
var tex = document.myform.comment.value;
var len = tex.length;
if(len > count){
tex = tex.substring(0,count);
document.myform.comment.value =tex;
return false;
}
document.myform.limit.value = count-len;
}
</script>
<!-- end of Script -->
************************************
HTML Code
In the body section put the below code :
************************************
<!-- Script -->
<form name="myform" METHOD="POST">
<table style="border: #CCFF99 5px solid">
<tr>
<td>
<textarea name=comment wrap=physical rows=3 cols=40 onkeyup=limiter() style="border:#CCFF66 1px solid"></textarea></td>
</tr>
<tr><td align="right">Character left:
<script language=javascript>
document.write("<input type=text name=limit size=4 readonly value="+count+">");
</script>
</td></tr></table>
</form>
<!-- Script -->
<form name="myform" METHOD="POST">
<table style="border: #CCFF99 5px solid">
<tr>
<td>
<textarea name=comment wrap=physical rows=3 cols=40 onkeyup=limiter() style="border:#CCFF66 1px solid"></textarea></td>
</tr>
<tr><td align="right">Character left:
<script language=javascript>
document.write("<input type=text name=limit size=4 readonly value="+count+">");
</script>
</td></tr></table>
</form>
<!-- Script -->
**************************************

Hope that it is useful.






it’s not working for me.firstly it was showing error in if(len >count) then i remove semicolon then error disappared but when i m running this, it’s not working for me..