Your Ad Here

Home » JavaScript »

0

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!-- 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 &gt; 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 :

************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!-- 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  -->

**************************************

counter

Hope that it is useful.


You may like these posts

    Multiple Upload files using php and javascriptSteps to implement and hosting your website in google app engine for freeHow to detect the javascript is enable or disable?How to request a cross domain ajax with in the js file

 

Leave a Reply