|
-
Aug 18th, 2003, 08:17 PM
#1
Thread Starter
Hyperactive Member
HTML: Text area [RESOLVED]
Is there a way, either with HTML or VBScript to limit the number of characters a user can enter in a text area?
Last edited by wolfrose; Aug 21st, 2003 at 11:15 AM.
-
Aug 18th, 2003, 11:48 PM
#2
New Member
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?
-
Aug 21st, 2003, 09:53 AM
#3
Frenzied Member
-
Aug 21st, 2003, 11:15 AM
#4
Thread Starter
Hyperactive Member
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>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|