Solved

Textarea Character Limit

Posted on 2011-09-07
4
279 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:gurvinder372
gurvinder372 earned 50 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 250 total points
ID: 36494524
0
 
LVL 31

Assisted Solution

by:Wayne Barron
Wayne Barron earned 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

710 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