aleart when done wtih form field

  • Thread starter Thread starter matt shudy
  • Start date Start date
M

matt shudy

Hi,

I am using the code below to limit the amount of text a
person can enter into a form field. Is there a way to
display an alert when they have reached the limit?

Thanks,

Matt

in the head
<script language="JavaScript" type="text/javascript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) field.value =
field.value.substring(0,
maxlimit);
else countfield.length = maxlimit - field.value.length;
}
</script>

in the body
<TEXTAREA onKeyDown="textCounter(this,this,250);"
onKeyUp="textCounter(this,this,250);" cols=80 name="FIELD"
rows=3
wrap=virtual></TEXTAREA>
 
I take it you copied this script? It would do you a lot of good to learn
JavaScript. In this case, it's a simple matter of adding the alert when the
condition is expressed in your "if" statement is true:

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
{
field.value = field.value.substring(0,maxlimit);
alert("Hey dummy, stop typing!");
}
else countfield.length = maxlimit - field.value.length;
}

--
HTH,

Kevin Spencer
..Net Developer
Microsoft MVP
http://www.takempis.com
Big things are made up
of lots of little things
 
Back
Top