Click to See Complete Forum and Search --> : textarea sizes


Count_Rugen
01-12-2003, 06:57 PM
is there a way to limit the amount of characters that can be entered into a textarea tag?

swon
01-12-2003, 07:31 PM
Hi, something like that can do it:

<textarea name="test" cols="20" rows="5" onKeypress="if(this.value.length>100){return false;}"></textarea>

I've edited this post, was a little bit inefficient ;-)

swon
01-12-2003, 08:36 PM
To check it also when someone is pasting some text it's better to make a function which could be like that:

<script language="JavaScript">
function testing(val,x){
maxlen = x;
if(val.length > maxlen){
alert('Limit of characters is '+ maxlen);
document.chars.tests.value = val.substring(0,maxlen);
}
}
</script>
<form name=chars action="">
<textarea name="tests" cols="20" rows="5" onBlur="testing(this.value,5)" onKeypress="testing(this.value,5)"></textarea></body>
</form>

the 5 is the maxlength of the characters!

Count_Rugen
01-12-2003, 10:11 PM
cheers, ill give it a go...