...

View Full Version : OnKeyDown event



Shindig
12-24-2004, 06:23 PM
I would like to know how to use the onkeydown event to record when I use the arrow keys.

Also, I would like that when my arrow keys are pressed, it goes to a link.


For example, if I pressed my up arrow key it would go to http://www.google.com, if I pressed my down arrow key it would go to http://www.yahoo.com, etc.

the key numbers are:

Left Arrow = 37
Up Arrow = 38
Right Arrow = 39
Down Arrow = 40

Thanks for any help. :)

mark87
12-24-2004, 07:09 PM
You'll want to do something like this -


<script language="javascript" type="text/javascript">
<!--
document.onkeydown = function keyPress(evt)
{
var keyCode =
document.layers ? evt.which :
document.all ? event.keyCode :
document.getElementById ? evt.keyCode : 0;
if (keyCode == 38)
{__doPostBack(document.location="http://www.google.com",'')}
else if (keyCode == 40)
{__doPostBack(document.location="http://www.yahoo.com",'')}
}
//-->
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum