I am imposing limit of characters in my textareas manually with this code:
<textarea onKeyDown="limitText(this.form.message,this.form.countdown,240);"
onKeyUp="limitText(this.form.message,this.form.countdown,240);"></textarea>
But I came to the conclusion that it is dirty and takes up space. I would like to use jQuery to be able to apply this limitText(this.form.message,this.form.countdown,240);
function to all existing textareas on my site.
The function limitText
is this
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
$("#countdown").html(limitField.value.length);
}
}