Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Onkeydown, but not if in a textbox

    Hi All,

    For my site I'm using this script:
    Code:
    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
    My Website
    010100010011110101110100011011110111000001101000

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    look here, especially the section: which element was clicked, http://www.w3schools.com/dhtml/dhtml_object_event.asp
    I am the luckiest man in the world

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks that helped a lot

    I've managed to fix my problem:

    Code:
    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
    My Website
    010100010011110101110100011011110111000001101000

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    the srcElement property of the event, is ofcourse IE-only (i believe) NS has the event.target property (again, i believe)

    mazzel
    I am the luckiest man in the world

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    My Website
    010100010011110101110100011011110111000001101000


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •