What is the best way to limit the amount of text that a user can enter into a \'textarea\' field on a web page? The application in question is ASP .NET, but a platform agnos
I use this, where the limit is a must. It also provides the user with the number of characters left.
function CountLength(vControl)
{
var strValue = vControl.value;
var vMax = 480;
var vLeft = vMax - strValue.length;
if (vLeft < 0)
{
vLeft = 0;
}
var vMessage = returnObjById('TextCounter');
if (document.all)
{
vMessage.innerText = vLeft + ' characters remaining.';
}
else
{
vMessage.textContent = vLeft + ' characters remaining.';
}
if (vLeft == 0)
{
vControl.value = vControl.value.substring(0, vMax);
}
}