Javascript onkeup() function that prevents entering more than X characters
function charsRemaining(evt, counterID, max) {
var chars = evt.getValue();
if (chars.length == 1 && chars[0] == '') { chars = []; }
var remaining = max - chars.length;
var counter = document.getElementById(counterID);
if (remaining >= 0) {
if(counter) counter.setTextValue(remaining + ' characters remaining');
}
else {
evt.setValue(evt.getValue().substr(0, max));
if(counter) counter.setTextValue((remaining * -1) + ' characters over');
}
}