Devo fare in modo che quando arriva a dieci caratteri rimanenti, si colora di rosso
HTML:
<script type="text/javascript">
charCount = 1; maxCharCount = 2000;
function displayRemLength(fieldName) {
remField = document.getElementById(fieldName);
remField.innerHTML = (maxCharCount - charCount > 0) ?
maxCharCount - charCount : 0;
}
function evalEntryLength(curField, maxLimit, discardXtra, errClass, normalClass {
maxCharCount = maxLimit;
var fieldLength = getCharCount(curField);
if (fieldLength > maxLimit) { if (errClass != "") {
curField.className = errClass;
}
if (discardXtra) {
showAllowedLength(curField, maxLimit);
}
}
else if (normalClass != "") {
curField.className = normalClass;
}
}
function getCharCount(curField) {
charCount = curField.value.length;
return charCount;
}
function showAllowedLength(curField, maxLimit) {
curField.value = curField.value.substr(0, maxLimit);
window.status = curField.value;
}
</script>
<span id="charCount">100</span> caratteri rimanenti
<textarea name="messaggio" id="text-guest" cols="0" rows="0" onkeyup="evalEntryLength(this, 100, true, '', ''); displayRemLength('charCount');></textarea>