textarea sizes

liunx

Guest
is there a way to limit the amount of characters that can be entered into a textarea tag?<!--content-->Hi, something like that can do it:<br />
<br />
<textarea name="test" cols="20" rows="5" onKeypress="if(this.value.length>100){return false;}"></textarea><br />
<br />
I've edited this post, was a little bit inefficient ;-)<!--content-->To check it also when someone is pasting some text it's better to make a function which could be like that:<br />
<br />
<script language="JavaScript"><br />
function testing(val,x){<br />
maxlen = x;<br />
if(val.length > maxlen){<br />
alert('Limit of characters is '+ maxlen);<br />
document.chars.tests.value = val.substring(0,maxlen);<br />
}<br />
}<br />
</script><br />
<form name=chars action=""><br />
<textarea name="tests" cols="20" rows="5" onBlur="testing(this.value,5)" onKeypress="testing(this.value,5)"></textarea></body><br />
</form><br />
<br />
the 5 is the maxlength of the characters!<!--content-->cheers, ill give it a go...<!--content-->
 
Back
Top