This script allows you to set a limit on the number of characters a user can enter into a textarea or text field, like so:
Insert the following code into the page head:
<script language="javascript" type="text/javascript">
if (limitField.value.length > limitNum)
{
limitField.value = limitField.value.substring(0, limitNum);
limitCount.value = limitNum - limitField.value.length;
}
else
{
limitCount.value = limitNum - limitField.value.length;
}
}
</script>
Step 2 - For Text Area
Use the following code to create the form and text area (if necessary, change the name of the form and text area to suit your needs):
<form name="myform"> <textarea name="limitedtextarea" onKeyDown="limitText(this,countdown,100);" onKeyUp="limitText(this,countdown,100);"> </textarea><br> <font size="1">(Maximum characters: 100)<br> You have <input readonly type="text" name="countdown" size="3" value="100"> characters left.</font> </form>
Step 2 - For Text Box
<form name="myform"> <input name="limitedtextfield" type="text" onKeyDown="limitText(this,countdown,15);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,15);" maxlength="15"><br> <font size="1">(Maximum characters: 15)<br> You have <input readonly type="text" name="countdown" size="3" value="15"> characters left.</font> </form>