Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

character limit on textarea (HTML or JavaScript) 1

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
Is there any way to set up a character limit on a text area in an HTML form? Is there any Javascript function that will work kind of as an OnMouseDown() event?
 
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd&quot;>[/URL]
<html>
<head>
<title>testbed</title>
<style type=&quot;text/css&quot;>
</style>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function check(txt) {
	if (txt.value.length > 50) {
		txt.value = txt.value.substr(0,50);
	}
}
</script>
</head>
<body>
<form>
<textarea name=&quot;bla&quot; rows=&quot;5&quot; cols=&quot;50&quot; onchange=&quot;check(this);&quot;>Max 50 chars</textarea>
</form>
</body>
</html>

or you could check onkeydown and catch them just as they hit the max chars/words.

See [b]Counting words in a textarea --- how?[/b] (thread216-599789)

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top