Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

How do you limit textarea of a form

( #14653=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on May 24, 2000 at 23:59 UTC
Q&A  > input and output


Description:

there is a textarea in a form that people seem to enjoy entering 5 spaces in between each line they type. this causes a problem when i print the info on paper that has preprinted info on it. Unlike the normal text box, MAXLENGTH is not an attribute of a textarea. Therein lies my problem

Answer: How do you limit textarea of a form
contributed by ZZamboni

Or if you want to remove blank lines:

s/\n{2,}/\n/g;
If you want to clump everything into a single line (maybe for reformatting it yourself, see Text::Wrap or my Nicely format a list or a string snippet):
s/\s+/ /g;
If you want to cut it to the first 5 non-empty lines:
$text=join("\n",(split(/\n+/,$text))[0..4])
I don't think there is an HTML attribute to restrict the number of lines in a TEXTAREA.

--ZZamboni

Answer: How do you limit textarea of a form
contributed by reptile

A possible perl solution is removing some of the newlines, like:

s/\n{3,}/\n\n/g;

which will replace three or more newlines in a row with two (two to preserve double-spacing of paragraphs).

Answer: How do you limit textarea of a form
contributed by newrisedesigns

In the text of the page, put "X character limit." Then $text = substr($text, 0, X)

You can also add the following as a guide to your form-submitters.

<input value="X" size="3" name="msgCL" disabled> <script language="JavaScript"> <!-- var supportsKeys = false function tick() { calcCharLeft(document.forms[0]) if (!supportsKeys) timerID = setTimeout("tick()",200) } function calcCharLeft(sig) { clipped = false maxLength = 200 //Change this. if (document.creator.signature.value.length > maxLength) { document.creator.signature.value = document.creator.signature. +value.substring(0,maxLength) charleft = 0 clipped = true } else { charleft = maxLength - document.creator.signature.value.length } document.creator.msgCL.value = charleft return clipped } tick(); //--> </script>

Hope this helps

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2014-11-23 02:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (127 votes), past polls