Home » » Characters Counter in Javascript

Characters Counter in Javascript

Written By Unknown on July 28, 2014 | Monday, July 28, 2014




You may have seen characters counter while sending messages from online free message benefits or in a few cases while topping off online enrollment forms.in this article you will figure out how to make character counter in javascript. 

Java Script

<script type="text/javascript">
//You can change the counter/limiter value as your wish
var count = "125";  
function limiter()
{
var textvalue = document.demoform.message.value;
var len = textvalue.length;
if(len > count){
tex = textvalue.substring(0,count);
document.demoform.message.value =tex;
return false;
}
document.demoform.limit.value = count-len;
}
</script>

HTML Code

<html>
  <body>
  <form method=""post"" name="demoform">
  <table>
  <tr><td><strong>Characters Counter Demo</strong></td></tr>
  <tr><td colspan="2"><textarea cols="40" name="message" onkeyup="limiter()" rows="3"></textarea></td></tr>
  <tr><td><label style="margin-left: 193px;">Characters left :</label></td> <td><input name="limit" readonly="" size="4" type="text" value="125" /></td></tr>
  </table>
  </form>
  </body>
</html>
Utilization: 1. Duplicate the javascript code and Paste it into the head piece of your HTML page.

2. You can undoubtedly set the utmost or counter as your wish.

3. On the off chance that you wish to limit the client not to sort more than 200 characters in textarea change the consider esteem 200. This will set the length or size of textarea.

0 comments:

Post a Comment