Is there a way, either with HTML or VBScript to limit the number of characters a user can enter in a text area?
Printable View
Is there a way, either with HTML or VBScript to limit the number of characters a user can enter in a text area?
use a javascript. there are two ways to implement it: on submission of form or, onkeypress.
running it onkeypress will use too much memory on the client side, so you are better off checking upon form submission. if you want to inform the user that he is over the limit as soon as he enters a character above the limit, then you will use onkeypress.
either way, check the length of the textarea control. use a decision structure: if length > allowedNumberOfCharacters then alert( "too long"); else return false;
...got the idea?
Sorry, I should have changed it. This is what I did:
<script language="javascript" type="text/javascript">
function maxLength( t, l ) {
if ( t.value.length >= l ) {
t.value = t.value.substring( 0, l - 1)
}
}
</script>
<textarea onkeypress="javascript:maxLength( this , 255 );" rows="6" name="likes" cols="54" value=""></textarea><BR>