textarea character counting question (javascript)

P

pduncan

Hi everyone,

I have a countChars function (javascript) for my textarea box: The
functions uses a textarea, and textbox. User is only allowed to type
up to "maxLength" characters in the textarea and the characters
remaining is displayed in the textbox.

function countChars(controlToValidateRef,
maxLength,outputControlRef, errorMessage,
enableClientSideRestriction,showJavascriptAlert,showCharacterCount)
{
var countString = maxLength - controlToValidateRef.value.length;
if (countString < 0) {
if (enableClientSideRestriction) {
controlToValidateRef.value =
controlToValidateRef.value.substring( 0, maxLength );
if (showJavascriptAlert) {
alert(errorMessage);
}
return false;
}
} else {
if (showCharacterCount) {
outputControlRef.value = countString;
}
}
}

I'm using this function for the following events
(onkeyup,onChange,OnFocus,OnBlur) of the textarea

This works in every scenario, except when a user uses the browser to
paste in text. Any way to detect this???

Thanks,
Paul
 
M

Martin Honnen

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top