Return to Snippet

Revision: 12856
at March 30, 2009 21:20 by hotdiggity


Initial Code
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en" dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>Limit Word Count in a textarea</title>
<script type="text/javascript"><!--
	var wordLen = 10; // Maximum word length
	function checkWordLen(obj){
	var len = obj.value.split(/[\s]+/);
	if(len.length > wordLen){
		alert("You've exceeded the "+wordLen+" word limit for the article!");
		obj.oldValue = obj.value!=obj.oldValue?obj.value:obj.oldValue;
		obj.value = obj.oldValue?obj.oldValue:"";
	return false;
	}
	return true;
	}
// --></script>
	</head>
	<body>
		<h1>JavaScript Example</h1>
		<p>This JavaScript sets a maximum word count to a textarea.</p>
		<form action="" method="get">
			<fieldset>
				<legend>Example Form</legend>
				<label>Text input: <br><textarea rows="15" cols="30" name="t1" onkeyup="checkWordLen(this);"></textarea></label>
				<input class="button" name="Submit" type="submit" value="Submit" />
				<input class="button" name="Reset" type="reset" value="Reset" />
			</fieldset>
		</form>
	</body>
</html>

Initial URL

                                

Initial Description

                                

Initial Title
Limit Word Count in a textarea

Initial Tags
css, javascript, html

Initial Language
JavaScript