Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: RE: Help with using OnKeyPress() to limit text insid a <textarea> box


Message #1 by "Albetski, Allan" <aalbetski@t...> on Mon, 15 Oct 2001 09:57:00 -0500
If you can use the TextRange object from IE, try this:

<body>
<textarea id="txtArea">This is my Text Area</textarea>
</body>
<script>
	var oTextRange = txtArea.createTextRange()
	alert(oTextRange.text.length)
</script>

-----Original Message-----
From: anhdo@a... [mailto:anhdo@a...]
Sent: Monday, October 15, 2001 11:45 AM
To: javascript
Subject: [javascript] Help with using OnKeyPress() to limit text inside
a <textarea> box


I want the Javascript to limit the characters in my textarea box to only 
255 characters.  This is the code I have below, but I can get it to work.  
Could someone help me out or tell me what I am doing wrong.  Thanks.



********
Req. Documents/Education: (255 characters max)<br>
<textarea cols="80" rows="4" name="qualifications" maxlength="255" 
onkeypress="ueditkeypressed(this)"></textarea>

<script language="JavaScript">
function uEditKeyPressed(poField)

if (poField.type=="textarea")
{
	if (poField.maxlength==0)
	{
		poField.maxlength=poField.rows*poField.cols;
	}
	if (poField.value.length>=poField.maxlength)
	{
		window.event.returnValue = false;
	}
	else
	{
		window.event.returnValue = true;
	}
}

</script>

  Return to Index