Hello,
I want 1 Textarea which can take only 20 characters. It can't input
more
than 20 characters.
Please, guide me.
Thanks in advance
well i shouldnt have said onchange of course! and im still not sure
how to trap the mouse paste event without using a messy interval
check, it wont be "live"
you could also provide user feedback using a disabled input, say:
<textarea name="textareaname" onkeyup="return checknumber()"
onfocus="checknumber()" onblur="checknumber()"></textarea>
<input disabled type="text" name="remaining" size="3" value=""/>
and the following function is called each time a user types somthing:
function checknumber()
{
var msgLen = 20;
var maxChars = msgLen;
var numChars = document.formname.textareaname.value.length;
if (numChars > maxChars)
{
document.formname.textareaname.value =
document.formname.textareaname.value.substring(0,maxChars);
numChars = maxChars;
document.formname.textareaname.focus();
r = false;
}
else {
r = true;
}
var c = numChars;
var numMsgs = 0;
while (c > 0)
{
numMsgs++;
c -= msgLen;
}
document.formname.remaining.value = maxChars - numChars;
return r;
}
you might have to print the textarea and input dynamically if the
input doesnt update as required.