aleart when done wtih form field

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>
 
K

Kevin Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top