Click to See Complete Forum and Search --> : character count in vbscript from asp


johannesburgboy
04-02-2003, 12:32 PM
I need to count the number of characters written in a <textarea name=basis id=basis></textarea>

Can anyone tell me how to pass the textarea to a VBScript function so that it will count the characters typed as I type.

SCRIPT language=VBScript>
Sub FunctionName(target)


Can I pass it as
<textarea onClick="FucntionName this"</textarea>

or soemthing like it.

Also after dong a count on it how do I access the field that will display the character count?

document.target.form1.fieldname ?

Please any suggestions will be appreciated

khaki
04-02-2003, 10:46 PM
Hi johannesburgboy...

I kinda ripped this (a bit un-elegantly) out of one of my pages that uses that type of script to update an Access table... but I think that it's complete enough as-is here.

Let me know if you still have trouble (this should do it, though).
;) k

The script:
<script language="javascript">
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</script>

The Text Area:
<textarea name=comments wrap=physical cols=22 rows=5 onKeyDown="textCounter(this.form.comments,this.form.remLen,255);" onKeyUp="textCounter(this.form.comments,this.form.remLen,255);"></textarea>

johannesburgboy
04-03-2003, 12:40 AM
Thanks guys. I appreciate this.