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
Solved

limiting number of lines of TextArea

Posted on 1997-08-25
3
887 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

766 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