var array = ["one", "two", "three"]; var button = 0; document.getElementById(array[button]).focus(); document.addEventListener('keydown', function onKeyDown(key) { if (key.keyCode == 40) {//up key button++;//needs code to keep it from going too high. document.getElementById(array[button]).focus(); } else if (key.keyCode == 38) {//down key button--;//it needs code to keep it from going too low. document.getElementById(array[button]).focus(); } else if (key.keyCode == 13) {//enter key //how do you run the button? } }, false); function myfun(){ window.alert("you pressed the button"); }