469,364 Members | 2,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

Keypressing Not Working

I can't figure out why my keypress script is not working. I used the
following code:

document.onkeypress = KeyCheck;

function KeyCheck(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
//alert(KeyID);
switch(KeyID) {
case 13: title(); break;
case 37: move(-1); break;
case 38: toggle(1); break;
case 39: move(1); break;
case 40: toggle(1); break;
}

}

Here's my results:
-----------------------------------------------------------------------
Firefox: | Works fine.
IE: | Enter key works but arrow keys don't trigger the function.
Opera: | No keypresses work.

When I experienced problems, I tested the keypressing with the alert
you see in the comments of the code, but aside from working in FireFox
and the initial enter keypress in IE, nothing happened.

The whole page can be seen at http://thegriddle.net/rcr/ if you need to
see any of the other functions or the HTML or CSS. Any ideas or
suggestions would be great :)

Aug 8 '06 #1
4 3656

Dave (DreamIsle) wrote:
I can't figure out why my keypress script is not working. I used the
following code:

document.onkeypress = KeyCheck;
Try:

document.onkeyup
Tested in IE and Firefox - sorry, no Opera here:

<div id="xx"></div>
<script type="text/javascript">

document.onkeyup = keyCheck;

function keyCheck(e) {
var e = e || window.event;
document.getElementById('xx').innerHTML = e.keyCode;
}
</script>
--
Rob

Aug 8 '06 #2
Sorry Rob, but that isn't working for me either. Even the enter key
won't work with that.

Aug 8 '06 #3

Dave (DreamIsle) wrote:
Sorry Rob, but that isn't working for me either. Even the enter key
won't work with that.
Please quote what you are replying to. The code I posted 'works' in IE
and Firefox, do you mean it doesn't work in Opera?

Maybe you have other stuff that is stopping the event from bubbling,
have you tried onkeydown?
--
Rob

Aug 8 '06 #4
The code that you posted did not work in Internet Explorer. I have
changed the code to onkeydown and the up and down arrow keys work in IE
now, but the left and right keys do not work.

------------------------------------

document.onkeydown = KeyCheck;

function KeyCheck(e) {
var e = e || window.event;
var KeyID = e.keyCode;
//alert(KeyID);
switch(KeyID) {
case 13: title(); break;
case 37: move(-1); break;
case 38: toggle(1); break;
case 39: move(1); break;
case 40: toggle(1); break;
}
}

Aug 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Gary | last post: by
6 posts views Thread by Mullin Yu | last post: by
8 posts views Thread by Hardy Wang | last post: by
5 posts views Thread by Martin Heuckeroth | last post: by
5 posts views Thread by tshad | last post: by
8 posts views Thread by jojobar | last post: by
2 posts views Thread by Don | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.