codice:
<script type="text/javascript">
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";

//non sono sicurissimo ma dovrebbe andare il senso è questo
var rimanenti = (parseInt(obj.getAttribute("maxlength"))-obj.value.length);

if (obj.getAttribute && obj.value.length>mlength)
     obj.value=obj.value.substring(0,mlength);

//qui se il tuo form si chiama "tuoForm" 
document.tuoForm.TXTcontatore.Value = rimanenti;
}
</script>
....
...
<textarea maxlength="40" onkeyup="return ismaxlength(this)"></textarea>
<input name="TXTcontatore" type="text" id="TXTcontatore" size="50">

Bhe dovrebbe andare ciao!