[thelist] Detecting certain keys input via JS

Jonathan Karlen jkarlen at infoniq.com
Fri Jul 9 00:29:55 CDT 2004

One immediate thought comes to mind...

Create a hidden form field to track the length of the value in the input
and compare against it.  If the value has decreased then it would seem
the only possibility is that the user has hit the backspace button (or
moused out some of the characters).

I wrote and tested the below to try out my hypothesis.  Please note it
uses onKeyUp instead of onChange.  onChange only fires once the field
has lost its focus or you click elsewhere on the screen.  onKeyUp causes
the evaluation to take place as soon as key is released.

Jonathan Karlen

<script language="javascript">
function checkPasswordField() {
	f.x.value = f.password.value.length
	if( f.password.value.length < f.lengthField.value) {
		f.password.value = "";
	f.lengthField.value = f.password.value.length;

<form id="f">
<input type="hidden" name="lengthField" value="1">
<input name="password" type="password" onKeyUp="checkPasswordField()">

Jonathan R. Karlen
President/Senior Developer
Infoniq E-Business Solutions, Inc.

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Jason Lustig
Sent: Thursday, July 08, 2004 10:17 PM
To: Thelist at Lists.Evolt.Org
Subject: [thelist] Detecting certain keys input via JS

Hi y'all

So I'm working on some more javascript UI stuff, and have been thinking 
a lot about password boxes.

I know that on Macs, if you hit backspace in a password box, it deletes 
everything in the box - presumably if you made a typo you should just 
start over.

I really like this functionality and want to give my password boxes it. 
I suppose I just need to set it up so that it's like:

<input type="password" name="foo" onchange="checkBackspace(this);"/>

... and just declare the function checkBackspace() to detect if a 
backspace was put in, and if so, clear this.value.

Any ideas on how to find out what the character input was?


* * Please support the community that supports you.  * *

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 

More information about the thelist mailing list