[Javascript] Q on interuppting char entry
David Lovering
dlovering at gazos.com
Fri Apr 11 17:16:46 CDT 2003
I personally like your method (I use it myself), as it is independent of
browser-specificity. However, if you want a
"clean" screen presentation, you can use the key.event handler at the next
layer down.
<input name='myButton' type='button' onKeyPress='do_key(event)'>
...
<script language='JavaScript'>
<!--
function do_key(evt) {
var charCode = (navigator.appName == "Netscape") ? evt.which :
evt.keyCode;
status = charCode;
if (charCode == <crap>) {
return false;
}
if (charCode == <goodStuff>) {
return true;
}
}
// -->
</script>
Obviously, <crap> and <goodStuff> should be replaced with the keycodes for a
character you want to destroy, or preserve (respectively). On most
platforms, this doesn't flash.
-- Dave Lovering
----- Original Message -----
From: "Walter Torres" <walter at torres.ws>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Friday, April 11, 2003 3:50 PM
Subject: [Javascript] Q on interuppting char entry
> 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
>
>
More information about the Javascript
mailing list