Question

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>
Was it helpful?

Solution

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.

OTHER TIPS

It is the browser, asking you if you want to disable repetitive alert messages. This is helpful in some development if, for example, an infinite loop is displaying alert messages. This gives a way to ignore that scenario. Otherwise it is a user aesthetic feature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top