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

x
?
Solved

Textarea Character Limit

Posted on 2011-09-07
4
Medium Priority
?
285 Views
Last Modified: 2012-06-21
I need a nice way to stop people from entering too many characters into a text box.  It would be nice if it worked for text that is too long that is copy-n-pasted into the textbox as well.  I am looking for an alert message that would come up when a limit was reached if possible.

Thank so muich.
0
Comment
Question by:Bob Schneider
[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
4 Comments
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 200 total points
ID: 36494519
its simple...give maxlength attribute to it
http://www.w3schools.com/tags/att_input_maxlength.asp

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 36494524
0
 
LVL 31

Assisted Solution

by:Wayne Barron
Wayne Barron earned 800 total points
ID: 36494536
This is what I use, it it works great.

Carrzkiss
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
</script>
</head>

<body>
<form>
<textarea name="ShortDesc" onKeyDown="limitText(this.form.ShortDesc,this.form.countShortDesc,3000);" onKeyUp="limitText(this.form.ShortDesc,this.form.countShortDesc,3000);"></textarea>
<input class="UpFF" readonly="readonly" type="text" name="countShortDesc" size="3" value="3000" />
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:Bob Schneider
ID: 36501767
Thanks.  The first solution is not allowed for text areas...or at least not recommended.  Regarding the last suggestion, I like it but it clears the textarea when you reach the maximum characters rather than just preventing more input.  Am I doing something wrong?
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

715 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