Count characters in Text box like way2sms.com
Some time in the normal world we need to type in text box just like way2sms.com. i.e. "160" character remaining. So to do this we need to do simple below JavaScript function.
<html>
<head>
<title>Type message just like 20 text is remaining</title>
<script type="text/javascript">
var maxLength = 160;
function charLimit(el) {
if (el.value.length > maxLength) return false;
return true;
}
function characterCount(el) {
var charCount = document.getElementById('charCount');
if (el.value.length > maxLength) el.value =
el.value.substring(0, maxLength);
if (charCount) charCount.innerHTML = maxLength -
el.value.length;
return true;
}
</script>
<style type="text/css">
#TextArea1
{
height: 81px;
width: 312px;
}
</style>
</head>
<body>
<table style="width: 100%;">
<tr>
<td align="right"
valign="middle">
<strong>Message :</strong>
</td>
<td style="margin-left: 40px">
<textarea
id="TextArea1"
onkeypress="return
charLimit(this)" onkeyup="return characterCount(this)"></textarea>
<p>
<strong><span id="charCount"
style="color: Red;">160</span></strong>
more characters available.
</td>
<td>
</td>
</tr>
</table>
</body>
</html>
No comments:
Post a Comment