Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

limiting number of lines of TextArea

Posted on 1997-08-25
3
Medium Priority
?
896 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 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

963 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