Saturday, 23 March 2013

Textarea field counting

TEXTAREA FIELD COUNTING...

This is a pretty useful yet easy to code :)

Working Demo:
Textarea counter
Letters remaining-


For this you will require a single html file with the following script.


<html>
    <head>
        <title>Textarea counter</title>
        <script type="text/javascript">
    function count(txtid){
        var limit = 150;
        var current = document.getElementById(txtid).value;
      if(current.length <= limit){
       
           document.getElementById("stat").innerHTML = limit - current.length;
        }
        else{
            alert("Dude max limit of letters reached");
         
        }
    }  
    </script>
 
 
    </head>
 
    <body>
        <textarea id="txt" onkeydown="count(id)" onkeyup="count(id)"></textarea><br>
        Letters remaining-
        <span id="stat"></span>
    </body>
 
</html>

No comments:

Post a Comment