Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Junior Member
    Join Date
    Jan 2004
    Posts
    8
    Member #
    4557
    How can I restrict the number of characters a user can input into a html form textarea?

    Cheers

  2.  

  3. #2
    Senior Member splufdaddy's Avatar
    Join Date
    Feb 2003
    Location
    Boston, MA
    Posts
    4,488
    Member #
    735
    Code:
    <input name="thebox" type="text" size="15" maxlength="10">

  4. #3
    Junior Member
    Join Date
    Jan 2004
    Posts
    8
    Member #
    4557
    Cheers but I'm after a multiline textarea: -

    <textarea name="comments" cols="23" rows="3" wrap="soft" id="textarea">

    Tried maxlength but didn't work

    Thanks

  5. #4
    Senior Member
    Join Date
    Dec 2003
    Posts
    1,274
    Member #
    4362
    wrap="soft" ??
    I think that what you need there is wrap="virtual"...

  6. #5
    Senior Member
    Join Date
    Dec 2003
    Posts
    1,274
    Member #
    4362
    The <textarea> element doesn't has any way to limit it's characters natively, you'll have to use javascript

  7. #6
    Senior Member
    Join Date
    Dec 2003
    Posts
    1,274
    Member #
    4362
    See this:
    Code:
    <TEXTAREA onkeyup="this.value = this.value.slice(0, xx)"></TEXTAREA>
    This script does that when you release the key, it will delete the characters that overpass "xx". It works in Firefox

  8. #7
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    You can achieve that by adding this simple javascript line:
    Code:
    <textarea name="textarea" onkeypress="return this.value.length < 30"></textarea>
    There's also a more complicated version here, that includes an additional box that counts down to zero as you approach the max number of characters allowed.

    EDIT:
    Didn't see Xarst post before I wrote this. His does basically the same, only on key up instead of down.
    S. Rosland


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:38 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com