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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

limit characters in scrolling text box

Status
Not open for further replies.

phentalmyst

Programmer
Jan 30, 2001
18
US
hey folks,

i was just wondering if there's a way to limit the amount of characters in a scrolling text box. i know in a single line box u just use maxlength, but that doesnt work in a scrolling one.

any help will be greatly appreciated!

thanks
 
king o' workarounds, luciddream with yet another great little function...

thread216-47301

lucid, if you read this, you know I mean no offense. It's a compliment.

:)
Paul Prewett
 
This code limits the textarea to 20 characters...

Code:
=============================================================================================
<html>
<head>
<title></title>

<script language=&quot;JavaScript&quot;>
var txtAreaChars = 0;
var notLimited = true;
var txtMax
var firstBit = &quot;&quot;;
function countArea()
{
 txtMax  = document.getElementById(&quot;txtArea&quot;).innerHTML;
	if (txtAreaChars < 20)
	{
		txtAreaChars+= 1;
		
	}
	else 
	{
		if (txtMax.length < 20)
		{
			notLimited = true;
			txtAreaChars = txtMax.length + 1;
		}
		else
			notLimited = false;
	}
}
</script>
</head>
<body>
<textarea id=&quot;txtArea&quot; rows=5 cols=40 onKeyPress=&quot;countArea(); return notLimited&quot;>

</textarea>
</body>
</html>
=============================================================================================
Klae

You're only as good as your last answer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top