2011-05-18

MaxLength on TextArea Input

Apparently, all these years I was wrong. I always thought that we could just put:
<TextArea MaxLength="30" /></TextArea>
to limit the size of a text input area.

When I tried it just now, then only I realised, in a pain way, that MaxLength wouldn't work for TextArea input! Oh my god! Now I have to resort to JavaScripts, which is very client dependent. Found a quick fix which raises event on keypress. Unfortunately, as I expected, you could still paste your long text into it. OnChange event just won't work.

What can I do now? :(

The code I have so far:
<script type="text/javascript">
function imposeMaxLength(Object,MaxLen) {
    return (Object.value.length <= MaxLen);
}  
</script>
and on TextArea input:

No comments:

Post a Comment