I have a textarea
, and my onkeypress
works just fine with hit.
However, if I keep trying to type the 256th character, my alert box eventually (2nd or 3rd time) also prints a little checkbox
that I did not write. It says
[] Prevent this page from creating additional dialogs
I'm confused as to whether the browser (Firefox) or Javascript is doing that. Here is the code.
function warnOverDescLen()
{
var misc_text = document.forms["InvGenPayDonation"]["TransDesc"].value;
if(255 < misc_text.length)
{
alert("You cannot enter more than 255 characters.");
return false;
}
return true;
}
.
.
.
<textarea rows="4" cols="60" name="TransDesc" id="TransDesc"
onkeypress="return warnOverDescLen();" ></textarea>
The browser adds that functionality to prevent sites from annoying users with a barrage of (thread-locking) popup messages.
To avoid the issue, I would recommend you display the message ("You cannot enter more than 255 characters.") in a small label near the text box instead of using alert
.