Textarea max rows and max characters per row

Discussion in 'Javascript' started by Greg Ferris, Jan 16, 2004.

  1. Greg Ferris

    Greg Ferris Guest

    I have read a number of posts with techniques for limiting the max
    number of characters entered into a textarea, but I'm looking for some
    advice on how to limit the number of rows and the number of characters
    per row.

    Basically, I need to allow users to enter up to 5 rows of data with up
    to 40 characters per row, regardless of whether or not the user has
    explicitly entered any line breaks. I also need to consider where to
    break off each line without breaking in the middle of a word.

    Any advice would be greatly appreciated.
     
    Greg Ferris, Jan 16, 2004
    #1
    1. Advertising

  2. Greg Ferris

    lallous Guest

    Hello,

    Basically, row1 and row2 are seperated by a new line character ("\n").
    Word wrapping visually shows multiple rows however it is still the same row.

    So to limit number of rows, simply count how much new line characters there
    are.

    To limit characters per row, simply scan each row and check its length.

    <script>
    t = "hello\n" +
    "world\n";

    lines = t.split('\n');
    </script>

    This script will create an array which holds every line...
    --
    Elias
    "Greg Ferris" <> wrote in message
    news:...
    > I have read a number of posts with techniques for limiting the max
    > number of characters entered into a textarea, but I'm looking for some
    > advice on how to limit the number of rows and the number of characters
    > per row.
    >
    > Basically, I need to allow users to enter up to 5 rows of data with up
    > to 40 characters per row, regardless of whether or not the user has
    > explicitly entered any line breaks. I also need to consider where to
    > break off each line without breaking in the middle of a word.
    >
    > Any advice would be greatly appreciated.
     
    lallous, Jan 16, 2004
    #2
    1. Advertising

  3. Greg Ferris

    Greg Ferris Guest

    Elias,
    Thank you for the help. The issue isn't what happens when a user
    enters a line break - I can detect that pretty easily. The issue is
    how I treat an entry WITHOUT line breaks. In other words, if the user
    types continuously, I need to then programatically create line breaks
    for the user (instead of just wrapping), still following the rules
    that there can only be five rows and 50 characters per row. Further,
    when creating these breaks, I want to be sure that I'm not doing it in
    the middle of a word.

    Thanks,
    Greg


    "lallous" <> wrote in message news:<bu8cvj$ej3o0$-berlin.de>...
    > Hello,
    >
    > Basically, row1 and row2 are seperated by a new line character ("\n").
    > Word wrapping visually shows multiple rows however it is still the same row.
    >
    > So to limit number of rows, simply count how much new line characters there
    > are.
    >
    > To limit characters per row, simply scan each row and check its length.
    >
    > <script>
    > t = "hello\n" +
    > "world\n";
    >
    > lines = t.split('\n');
    > </script>
    >
    > This script will create an array which holds every line...
    > --
    > Elias
    > "Greg Ferris" <> wrote in message
    > news:...
    > > I have read a number of posts with techniques for limiting the max
    > > number of characters entered into a textarea, but I'm looking for some
    > > advice on how to limit the number of rows and the number of characters
    > > per row.
    > >
    > > Basically, I need to allow users to enter up to 5 rows of data with up
    > > to 40 characters per row, regardless of whether or not the user has
    > > explicitly entered any line breaks. I also need to consider where to
    > > break off each line without breaking in the middle of a word.
    > >
    > > Any advice would be greatly appreciated.
     
    Greg Ferris, Jan 16, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S01aX3N0YXRl?=

    Quick one - Is SESSION per browser instance or per IP Address?

    =?Utf-8?B?S01aX3N0YXRl?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,944
    gerry
    Apr 10, 2006
  2. Razvan
    Replies:
    1
    Views:
    437
    tony vee
    Sep 10, 2004
  3. Replies:
    5
    Views:
    2,631
  4. Peter
    Replies:
    1
    Views:
    2,385
    John B. Matthews
    Jan 19, 2010
  5. ethem
    Replies:
    1
    Views:
    1,232
    Ashok Kunwar Singh
    Mar 2, 2011
Loading...

Share This Page