Count and Limit Character Input in Text Boxes
characters left
characters left
Put this in between the <head> and</head> tags:
<SCRIPT LANGUAGE="JavaScript"> <!-- Begin function twdCount(field,cntfield,maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else cntfield.value = maxlimit - field.value.length; } // End --> </script>
Here is the form code:
<form name="myForm" action="yourpage.asp" method="post"> <textarea name="txtbox1" wrap="physical" cols="28" rows="1" onKeyDown="twdCount(document.myForm.txtbox1,document.myForm.twd1,25)" onKeyUp="twdCount(document.myForm.txtbox1,document.myForm.twd1,25)"></textarea> <br> <input readonly type="text" name="twd1" size="2" maxlength="25" value="25"> characters left <br><br> <textarea name="txtbox2" wrap="physical" cols="28" rows="4" onKeyDown="twdCount(document.myForm.txtbox2,document.myForm.twd2,125)" onKeyUp="twdCount(document.myForm.txtbox2,document.myForm.twd2,125)"></textarea> <br> <input readonly type="text" name="twd2" size="3" maxlength="3" value="125"> characters left <br><br> <input type="Submit" name="Submit" value="Submit"> </form>