How to restrict the number of lines in a text area ?

A

Anz

Is it possible to limit the number of lines in a text area ?,
I have a text area, in which i have to limit the number of lines up to
3,
How can i done this?, I wrote the tag as

<textarea name="short_desc" id="short_desc" cols="25" rows="3" ></
textarea>

But this doesn't help me, pls reply
 
B

BootNic

On Mon, 30 Jun 2008 22:05:26 -0700 (PDT)
Is it possible to limit the number of lines in a text area ?, I have
a text area, in which i have to limit the number of lines up to 3,
How can i done this?, I wrote the tag as

<textarea name="short_desc" id="short_desc" cols="25" rows="3" ></
textarea>

But this doesn't help me, pls reply

Are you sure you just want to limit the number of rows in a textarea?
Perhaps a silly question.

However if you decide you wish to limit the number of charters in the
textarea, with the aid of javascript, you may find what you need from
google.

http://tinyurl.com/3n44us

Keep in mind it will still need to be checked on the server.




--

BootNic Tue Jul 1, 2008 02:01 am
If the facts don't fit the theory, change the facts.
*Albert Einstein*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkhpyE4ACgkQylMUzZO6jeJlvQCggCn/nL7uLAu8+ShKFmlfrUuD
HggAn1BPNNczXZTVEXJP5zQKtOzhm/1F
=OKrO
-----END PGP SIGNATURE-----
 
A

Anz

Thanks, i just want to limit the number of lines in the text
area, ...not the chars
 
B

BootNic

On Mon, 30 Jun 2008 23:11:23 -0700 (PDT)
Thanks, i just want to limit the number of lines in the text area,
...not the chars

Interesting. Well all is not lost just yet. You can still have a look
at some of them examples, pick on you kind of like.

Then after that all one has to do is count line returns in place of the
charters.

Go make yourself an example page to share with everyone in the
newsgroup, try to modify one of the scripts to do what you need it to.

Then when you need help with it, try posting in comp.lang.javascript.

--

BootNic Tue Jul 1, 2008 02:21 am
Have no fear of perfection - you'll never reach it.
*Salvador Dali*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkhpzPYACgkQylMUzZO6jeIZdgCfelImD3EAgCJIcEIiEU/suEAP
Zm0An2gfUCaLWvMoK+B6U2U6gWidp77t
=jVrN
-----END PGP SIGNATURE-----
 
A

Adrienne Boswell

Thanks, i just want to limit the number of lines in the text
area, ...not the chars

Please understand there really is no way to count LINES, only characters.
Why? Because the width of a character can change with the UI. Ever had a
word document that was one page and a second page with a little bit of
text? To fit it all on one page, Word first reduces the font size. So, you
see, you really cannot use lines.

Additionally, most people are used to see _characters_. What you _can_ do
is state something like:
Maxium characters is 200, about 4 lines. Then include javascript that
counts the characters and presents how many are left. Of course, you will
have to check the amount of characters server side.
 
J

Jonathan N. Little

Anz said:
Thanks, i just want to limit the number of lines in the text
area, ...not the chars

Cannot be done with HTML. Must count new line characters, first with
JavaScript then finally with server-side...
 
T

the_mighty_snap_dragon

Is it possible to limit the number of lines in a text area ?,
I have a text area, in which i have to limit the number of lines up to
3,
How can i done this?, I wrote the tag as

<textarea name="short_desc"  id="short_desc" cols="25" rows="3" ></
textarea>

But this doesn't help me, pls reply

Hi, i've had to solve this problem today. Its true that you can't
solve this with HTML. But the javascript to achieve it is quite
simple, my solution is as follows:

This is for a textarea that is being used as an address entry box, i'm
limiting it here to four lines but you can change it to whatever size
you need

1) Attach some javascript to the onkeyup event of the textarea
2) Split the textarea string into an array using split() on the \n
char
3) Count the number of lines in the textarea by getting the number of
elements in the newly created string array
4) Setting the value of the text area equal to lines 1,2,3
5) Making the string in the array for line 4 equal to a substring of
itself that is missing the last character (else you end up with 4
lines and a newline)
6) Output a notice to the user that the input field has too many
lines.

The code looks like this:
onkeyup="var newlineCount = this.value.split('\n');
if(newlineCount.length>4) { this.value =
newlineCount[0]+newlineCount[1]+newlineCount[2]+
(newlineCount[3].substr(0,newlineCount[3].length-1)); alert('Maximum
Address Size: Four Lines');}"

Hope this is useful,

Regards,
John.
 
J

Jukka K. Korpela

Scripsit Jonathan N. Little:
Cannot be done with HTML. Must count new line characters, first with
JavaScript then finally with server-side...

So, as so often, the _real_ question is what the OP is doing. What is
the pragmatic goal, and how can you illustrate with a URL?

Moreover, _if_ restrictions are really needed, they should _first_ be
implemented server-side, because there they can work reliably.

Then you might consider using three single-line input fields, possibly
with maxlength attributes. This will _not_ ensure that data is within
the limitations, since anyone and his brother can create a modified
version of the form and submit any data he wants. But it may help normal
users to understand the limitations and live with them.
 
A

Anz

Is it possible to limit the number of lines in a text area ?,
I have a text area, in which i have to limit the number of lines up to
3,
How can i done this?, I wrote the tag as
<textarea name="short_desc" id="short_desc" cols="25" rows="3" ></
textarea>
But this doesn't help me, pls reply

Hi, i've had to solve this problem today. Its true that you can't
solve this with HTML. But the javascript to achieve it is quite
simple, my solution is as follows:

This is for a textarea that is being used as an address entry box, i'm
limiting it here to four lines but you can change it to whatever size
you need

1) Attach some javascript to the onkeyup event of the textarea
2) Split the textarea string into an array using split() on the \n
char
3) Count the number of lines in the textarea by getting the number of
elements in the newly created string array
4) Setting the value of the text area equal to lines 1,2,3
5) Making the string in the array for line 4 equal to a substring of
itself that is missing the last character (else you end up with 4
lines and a newline)
6) Output a notice to the user that the input field has too many
lines.

The code looks like this:
onkeyup="var newlineCount = this.value.split('\n');
if(newlineCount.length>4) { this.value =
newlineCount[0]+newlineCount[1]+newlineCount[2]+
(newlineCount[3].substr(0,newlineCount[3].length-1)); alert('Maximum
Address Size: Four Lines');}"

Hope this is useful,

Regards,
John.

Thank u Mr. John
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top