TextArea not working

I have a text area and set the max length as I was told to do with w3c but it’s not working. I can type for ever without the limit being inforced. I don’t know what I did wrong.


<textarea id="userString" name="userString" maxlength="150" rows="5" cols="50"></textarea>

Dang, Thanks.

I will either use JavaScript or PHP to validate then.

I think he refers to the max chars on a textfield. You can set the number of cols. If you would like to limit the number of characters you could use javascript:

<script type="text/javaScript">
<!--
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}
//-->
</script>
<textarea name="description" onkeyup="textCounter(this.form.description,2500);" onkeydown="textCounter(this.form.description,2500);" rows="5" wrap="virtual" id="description" cols="30"></textarea>

donboe’s correct: textarea does not have a maxlength attribute, and you need to use Javascript to get that functionality.

I’ve written similar Javascript, but what I did was let the input be a text input with a maxlength attribute, and if JS was enabled, switch that over to a textarea and let JS limit the chars.

Does textarea have a maxlength attribute?

Validation always needed a script. Never rely on markup to filter input. Never.

Anyone with a text editor and a bit of knowhow can change your maxlength anyway.

You should use the back end to validate, otherwise anyone without Javascript enabled will be able to send you unchecked input.