Solved

limiting number of lines of TextArea

Posted on 1997-08-25
3
872 Views
Last Modified: 2008-03-03
Can we limit the number os lines user can type in textarea
using javascript? Thx.
0
Comment
Question by:speed2
3 Comments
 
LVL 2

Accepted Solution

by:
dmethvin earned 100 total points
ID: 1269163
I guess you're trying to prevent a message from being too long? You could always count newlines or just prevent the length of the entire string from being longer than some size.

I think something like the following would do both; I haven't checked this so consider it a serving suggestion:

var s = form.text.value;
if ( s.length > 100 ) alert("don't type so much");

var lines = 1;
var i = -1;
while ( ( i = s.indexOf("\n",i+1) >= 0 )  lines++;
if ( lines > 10 ) alert("too many lines");

0
 
LVL 1

Expert Comment

by:pmcintos
ID: 1269164
Thanks for answers from both of you. I guess my question is
how can I let the user know when they are still typing. "onChange" will only be activated if the user onFocus from the
textArea field. Thx a lot.

0
 

Author Comment

by:speed2
ID: 1269165
It isn't possible any other way using javascript.....
Perhaps if you need this level of protection in your textarea you should investigate putting your form in a java applet.
This would enable you to do a lot more rigorous checking on the textarea.
Your right though on most browsers the onChange method of the textarea isn't really called on every change.  This is kind of misleading for this event handler.

Good luck
Pete
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now