Wednesday, May 13, 2009

Javascript Text Counter

Here is the javascript text counter that you write down the text in TEXTAREA box,it show the available text count. Put the javascript between <head> and </head>.

//Handle textarea comment and URL description character count
<script type="text/javascript">
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</script>

<span>Comments:</span>
<span>Only 200 char allowed</span>
<textarea id="COMMENTS" onblur="this.style.backgroundColor='#ffffff'" onfocus="this.style.backgroundColor='#FFFCF9'" onkeyup="textCounter(this.form.COMMENTS,this.form.remLen,200);" onkeydown="textCounter(this.form.COMMENTS,this.form.remLen,200);" rows="7" cols="60" name="COMMENTS" style="background-color: rgb(255, 255, 255);">
</textarea>
<input type="text" readonly="" value="200" maxlength="3" size="3" name="remLen"/>
<span>Char count</span>

0 comments:

Post a Comment