[thelist] Detecting certain keys input via JS
Sarah Sweeney
mr.sanders at designshift.com
Fri Jul 9 10:24:15 CDT 2004
Jason Lustig wrote:
> 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?
This should allow you to "catch" the backspace keypress:
function catchKeypress(e)
{
if (e.keyCode == 8)
{
//do whatever...
}
}
document.onkeydown = catchKeypress;
--
Sarah Sweeney
Web Developer & Programmer
Portfolio :: http://sarah.designshift.com
Blog, etc :: http://hardedge.ca
More information about the thelist
mailing list