[Javascript] Count textbox characters
Tim Makins
spindrift at oceanfree.net
Sat Nov 13 05:14:22 CST 2004
Here's a useful tool I found on one of the PayPal pages - it tells the user
how many characters are left in a textbox.
Tim in Ireland.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
</head>
<body>
<script language=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>
<form name="f1" action="" method="post">
Type your information in this box (1000 characters max.)<br>
<textarea name="message" cols="65" rows="11"
onKeyDown="textCounter(this.form.message,this.form.remLen,1000)"
onKeyUp="textCounter(this.form.message,this.form.remLen,1000)">
</textarea><br>
<input readonly type="text" name="remLen" size="4" maxlength="4"
value="1000">
characters left<br>
</form>
</body>
</html>
More information about the Javascript
mailing list