
Originally Posted by
javascripter
Hi , I have found bug in textarea maxlength code.
If you intend to limit entry lengths, do so in response to the change and submit events:
Code:
var maximumLength = 40;
function checkLength(control, maximum) {
var length = control.value.length;
if (length > maximum) {
alert('Please limit your message to ' + maximumLength
+ ' characters. There are currently ' + length + '.');
return false;
}
return true;
}
function validate(form) {
var controls = form.elements;
if (!checkLength(controls.textArea, maximumLength))
return false;
return true;
}
HTML Code:
<form action="..." onsubmit="return validate(this);">
<!-- ... -->
<textarea ... onchange="checkLength(this, maximumLength);"></textarea>
<!-- ... -->
</form>
Mike
Bookmarks