Results 1 to 4 of 4

Thread: HTML: Text area [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member wolfrose's Avatar
    Join Date
    Aug 2002
    Location
    Indiana
    Posts
    309

    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.

  2. #2
    New Member
    Join Date
    Aug 2003
    Location
    sunnyvale, ca (NOT CANADA)
    Posts
    2
    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?

  3. #3

  4. #4

    Thread Starter
    Hyperactive Member wolfrose's Avatar
    Join Date
    Aug 2002
    Location
    Indiana
    Posts
    309
    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
  •  



Click Here to Expand Forum to Full Width