...

View Full Version : Onkeydown, but not if in a textbox



chrisvmarle
02-26-2003, 12:01 PM
Hi All,

For my site I'm using this script:

function check_key() {
kc = event.keyCode
if(kc>=65 && kc<=90) {
chr = String.fromCharCode(kc).toLowerCase()
document.location.href = "#" + chr
}
return true
}
document.onkeydown=check_key;

The problem is, if this script is active I'm unable to enter anything in a textbox

I'm almost sure there's a way to check event for the selected type of the document (wich would be "text" for <input type="text">). If someone could tell me how to do that I know how to handle the rest :)

Thanks in advance
Mzzl, Chris

Roelf
02-26-2003, 12:36 PM
look here, especially the section: which element was clicked, http://www.w3schools.com/dhtml/dhtml_object_event.asp

chrisvmarle
02-26-2003, 12:59 PM
Thanks that helped a lot :)

I've managed to fix my problem:



function check_key() {
tname=event.srcElement.tagName
if (tname == "INPUT") return true
kc = event.keyCode
if(kc>=65 && kc<=90) {
chr = String.fromCharCode(kc).toLowerCase()
document.location.href = "#" + chr
}
return true
}
document.onkeydown=check_key;

Mzzl, Chris

Roelf
02-26-2003, 01:56 PM
the srcElement property of the event, is ofcourse IE-only (i believe) NS has the event.target property (again, i believe)

mazzel

chrisvmarle
02-26-2003, 02:42 PM
It's no problem it's IE-compatible only, since I'm using this on a page I use to list some files in a personal directory on my webserver. It's just a personal page only I can view (and I'm using IE ;))

Mzzl, Chris

P.S. Thanks for the advise anyway :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum