Solved

limiting number of lines of TextArea

Posted on 1997-08-25
3
894 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…
Suggested Courses

630 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