Limit entry into TextArea

Discussion in 'Javascript' started by JohnSouth, Jan 31, 2006.

  1. JohnSouth

    JohnSouth Guest


    In a TextBox I can set a maximum size for the entry.
    Is there a way of limiting the number of characters being entered into
    a TextArea control?

    John South
    JohnSouth, Jan 31, 2006
    1. Advertisements

  2. JohnSouth

    impaler Guest

    <textarea onkeypress="if (this.value.length > 200) this.value =
    this.value.substr(0, 200);">

    do this on onblur too, to avoid copy paste and if there are other
    scenarios to put more too.
    impaler, Jan 31, 2006
    1. Advertisements

  3. Why not limit length of input in the first place?

    <textarea onkeypress="return (this.value.length <= 200);"></textarea>

    where the parens are not necessary. This should be extended to tell
    the user why the number of characters is limited.

    Thomas 'PointedEars' Lahn, Jan 31, 2006
  4. JohnSouth

    impaler Guest

    It's a javascript topic so I thought he wants a javascript solution :)
    impaler, Feb 1, 2006
  5. You are talking nonsense. Mine *is* a JavaScript solution as well, which,
    in contrast to yours, limits the length of input on the first place rather
    than correcting the value afterwards. And any solution for this problem
    cannot qualify as a JavaScript solution alone, because the DOM is involved

    Learn to quote.

    Thomas 'PointedEars' Lahn, Feb 1, 2006
  6. JohnSouth

    JohnSouth Guest

    Thanks to All. It's clear to me now, and it makes a big improvement to
    the entry screen.

    John South
    JohnSouth, Feb 4, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.