In previous articles I explained JavaScript restrict user to enter only numbers, JavaScript allow limited characters in textarea, JavaScript remove special characters from textbox JavaScript validations for phone, email and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to show number of characters remaining in textbox or textarea using JavaScript.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Limit
the number of characters in textbox or textarea</title>
<script type="text/javascript">
function LimtCharacters(txtMsg, CharLength, indicator)
{
chars = txtMsg.value.length;
document.getElementById(indicator).innerHTML =
CharLength - chars;
if (chars > CharLength) {
txtMsg.value = txtMsg.value.substring(0,
CharLength);
}
}
</script>
</head>
<body>
<div style="font-family:Verdana; font-size:13px">
Number of Characters Left:
<label id="lblcount"
style="background-color:#E2EEF1;color:Red;font-weight:bold;">140</label><br/>
<textarea id="mytextbox" rows="5" cols="25" onkeyup="LimtCharacters(this,140,'lblcount');"></textarea>
</div>
</body>
</html>
|
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
3 comments :
thanks its good
thanks its good
It was not working while using master page