This script counts characters from a <textarea>. I’m told it’s inline and somehow deficient even though it works. I admit I don’t like the use of the this keyword because I really don’t understand its use. How could I rewrite this script to make it more this century?
[code=html]<html>
<head>
<script language=”javascript” type=”text/javascript”>
var maxAmount = 250;
function textCounter(textField, showCountField) {
if (textField.value.length > maxAmount) {
textField.value = textField.value.substring(0, maxAmount);
} else {
showCountField.value = maxAmount – textField.value.length;
}
}
</script>
</head>
<body>
<form>
<textarea name=”ta” rows=”6″ style=”width:340px;” onKeyDown=”textCounter(this,document.getElementById(‘ta2’));” onKeyUp=”textCounter(this,document.getElementById(‘ta2’));”></textarea>
<br>
<input readonly id=”ta2″ type=”text” name=”countDisplay” size=”3″ maxlength=”3″ value=”250″> Characters Remaining
</form>
</body>
</html>