Mr. x said:
Hello,
How can I limit the maximum characters that can be entered in the
<textArea> (using html attributes) ?
Thanks
With a single line ( input type="text" ) you can use maxlength="10" as
attribute. Not with a textarea.
With a textarea you will need some javascript. Here is an example:
---- javascript example ----
<html><head>
<script type="text/javascript" language="JavaScript">
function calcCharLeft(theForm)
{
var mytext = theForm.thetext.value;
var availChars = 140;
if (mytext.length > availChars) {
theForm.thetext.value = mytext.substring(0,availChars);
theForm.fChars.value = 0;
alert('Your text is too long');
theForm.thetext.focus();
}
else {
theForm.fChars.value = availChars - mytext.length;
}
}
</script>
<title>limit chars</title>
</head>
<body>
<form method="post" action="yoururl" name="myForm">
<textarea name="thetext" rows="7" cols="26" onkeypress="calcCharLeft
(this.form)" onkeyup="calcCharLeft(this.form)" onkeydown="calcCharLeft
(this.form)" onchange="calcCharLeft(this.form)"></textarea>
<input class="disabled" align="right" type="text" name="fChars"
size="4" value="140" disabled onfocus="this.form.msg.focus()">
</form>
</body></html>
---- end javascript example ----
Cheers,
Louis