Solved

Textarea Character Limit

Posted on 2011-09-07
4
268 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
4 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 50 total points
Comment Utility
its simple...give maxlength attribute to it
http://www.w3schools.com/tags/att_input_maxlength.asp

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
Comment Utility
0
 
LVL 30

Assisted Solution

by:Wayne Barron
Wayne Barron earned 200 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now