[Javascript] Q on interuppting char entry

BEKIM BACAJ trojani2000 at hotmail.com
Sat Apr 12 13:09:24 CDT 2003


I admire your script, but it's to messy for me.
I vould rather simply set the maxLength var for the text input and then 
retrieve the length from last onkeyup event to se if the maxLength is met, 
and then set the onkeypress to false, -no other character will ocur and you 
will get rid of that 'flash' forever.

So, try to return the keypress to false after the char limit is met.

Cheers!



>From: "Walter Torres" <walter at torres.ws>
>Reply-To: "[JavaScript List]" <javascript at LaTech.edu>
>To: "[JavaScript List]" <javascript at LaTech.edu>
>Subject: [Javascript] Q on interuppting char entry
>Date: Fri, 11 Apr 2003 16:50:41 -0500
>
>I am trying to create a method that limits the character count in a
>TEXTAREA, like MAXLENGTH does in TEXT and PASSWORD.
>
>What I have works (see below), to a point.
>
>What it does is allow another character to flash in the box, and then it is
>removed.
>
>Anyone have any idea on how to interrupt this character entry at this 
>point,
>thus no character flash?
>
>Thanks
>
>Walter
>
>=================
>
>var objTA = [favorite method to get Element Reference]
>
>objTA.onkeypress = setLimit;
>objTA.onkeydown  = setLimit;
>objTA.onkeyup    = setLimit;
>
>function setLimit ( )
>{
>    // Get name of given TEXTAREA
>    var strName = this.id;
>
>    // What is the limit set at for this TEXTAREA
>    var intLimit = new Number ( this.getAttribute("maxlength") );
>
>    // How many characters do we have yet?
>    var intCharRemaing = new Number ( intLimit - this.value.length );
>    if ( intCharRemaing < 0 )
>    {
>       this.value = this.value.substring( 0, intLimit  );
>       intCharRemaing = 0;
>    }
>}
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript


_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



More information about the Javascript mailing list