I have javascript code that counts characters as they are typed into a textarea and tells the user how many of the 480 maximum allowable chracters are left.
This page is posted to a confirmation page where the user can submit or edit the variables. In the edit page, the characters were not being counted. I got the following code from a prior posting on this forum.
[code]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title></title>
<script language=”JavaScript” type=”text/javascript”>
<!–
function Left(taid,tbid){
document.getElementById(tbid).value=480-document.getElementById(taid).value.length+’ Left’;
}
//–>
</script></head>
<body onload=”Left(‘fred’,’tom’);” >
<textarea id=”fred” name=”message” wrap=”hard” cols=70
rows=10 width=”120″ onKeyDown=”textCounter(this.form.message,this.form.remLen,480);”
onKeyUp=”textCounter(this.form.message,this.form.remLen,480);”><?php $message = print(ltrim(stripslashes($message))); ?></textarea>
<br><br>
You have <input readonly id=”tom” type=text name=remLen size=3 maxlength=3 value=”480″> characters left
</body>
</html>
This works BUT it seems to count something other than just the characters so it comes up with 1-10 fewer characters left than was shown on the original form. ALSO, it doesn’t subtract characters deleted or add characters added on the edit page.
Any ideas on how to make the count correct to start and allow it to change as the textarea content is edited?
Thanks loads, in advance, for any assistance.