?earler?? This was my first post in this thread.
FWIW, you have two choices: Leave the JS code as it is, or indeed put in your function, thus:
document.onkeydown = checkKey;
function checkKey( ev )
ev = ev || event;
key = ev.keyCode;
alert ("Keycode = " + key); // for testing
if(key == 38)
alert('up arrow are working');
else if(key == 40)
alert('down arrow are working');
The two are 100% equivalent.