Click to See Complete Forum and Search --> : Character Limitation


jordanj
06-25-2003, 12:02 PM
Hello,

I'm using a script on a form that limits the number of charatcers used in a textarea field. I currently have set the textarea to a limit of 255 characters. I have noticed that when a user does a copy and paste of content that is more than 255 characters, the extra characters will be added to the textarea field. But if a user types in the conetent, it will max out at 255.

Is there a way to setup the script or the textarea so if a user types or does a copy and paste, the content will max at 255 only?

-Javascript-

<!-- Begin
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
// End -->


-Textarea Code-

<textarea name="quick_bio" wrap="virtual" cols="51" rows="5"
onKeyDown="textCounter(document.form.quick_bio,document.form.remLen1,255)"
onKeyUp="textCounter(document.form.quick_bio,document.form.remLen1,255)">
</textarea>

Thanks;

CrazyGaz
06-25-2003, 12:06 PM
the way I would do it is.

<script language="javascript">
function validate() {

if (document.form1.txtarea1.value.length > 255 ){
alert("you cannot exceed 255 characters")

return false;
}
}
</script>

<form action=***URL*** onSubmit="return validate();"

<textarea name="txtarea1"></textarea>

hope this helps, Gaz

Charles
06-25-2003, 02:38 PM
<textarea name="quick_bio" wrap="virtual" cols="51" rows="5"
onkeydown="textCounter(document.form.quick_bio,document.form.remLen1,255)"
onkeyup="textCounter(document.form.quick_bio,document.form.remLen1,255)"
onchange="textCounter(document.form.quick_bio,document.form.remLen1,255)">
</textarea>