Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Textarea Character Limit

Posted on 2011-09-07
4
Medium Priority
?
287 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: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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
Suggested Courses

963 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