Get remaining characters count in a textbox using javascript | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

Get remaining characters count in a textbox using javascript

Wednesday


Show how many characters remaining in a html text box using javascript:
                                                                                     The following  javascript will help you to show how many characters are remaining for a textbox or textarea, The label placed next to the text box shown the number of character remaining.

<script type="text/javascript">
function txtCounters(id,max_length,myelement)
{
counter 
= document.getElementById(id);
field = document.getElementById(myelement).value;
field_length field.length;
 if 
(field_length <max_length)  {
//Calculate remaining characters
 
remaining_characters max_length-field_length;
//Update the counter on the page
  
counter.innerHTML remaining_characters;  }
 } 
</script>

<label for="txtName">Enter Your Text : </label>
<input type="text" id="txtName" size="50" maxlength="50" onkeyup="javascript:txtCounters('txtCounter',50,'txtName')"> <div id="txtCounter"><b>50</b></div>characters remaining.
Demo:

50
chars remaining.

0 comments:

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets