Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

limiting number of lines of TextArea

Posted on 1997-08-25
3
Medium Priority
?
895 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

721 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