Solved

Textarea Character Limit

Posted on 2011-09-07
4
273 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
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 30

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Call a function within the ASP code 4 19
Create an automated page index 9 47
Html fieldset fix its height and width 4 27
Html Table Looping (part 2) 5 27
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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…

809 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