But then your check doesn't occur until the user moves off of the field.
And while you could capture keystrokes, how does that help if the user copy/pastes something in using only the mouse?
The best answer, I think, is something like this:
Code:
<script>
var MAXSIZE = 200;
function checkTAsize( )
{
var fld = document.FormName.FieldName;
if ( fld.value.length > MAXSIZE )
{
fld.value = fld.value.substring(0,MAXSIZE);
alert("Only " + MAXSIZE + " characters allowed"); // message is optional of course
}
}
</script>
...
<body onload="setInterval('checkTAsize()', 250);">
...
Having said all this...
Why would you use a TEXTAREA for a ONE LINE field value like First Name????
Just use
Code:
<input name="name" size="20" maxsize="20" />
And the browser won't allow more than maxsize characters to be entered. No
JS needed.