I am trying to navigate a list using the up and down keys. And when the up or down key is pressed, information about the highlighted item should be shown to the user. The code examples I've found aren't clear to me or don't address my problem. This is the best code I can find (that I sort of understand):
But this code is not linked to my list. And I can't work out how to do that. Here is my HTML:
I am completely new to javascript and I was hoping someone could help me out with this problem because I'm out of ideas. Thanks for any help!
JavaScript:
document.addEventListener('keydown', function(event) {
if(event.code == 'KeyZ' && (event.ctrlKey || event.metaKey)) {
alert('Undo')
}
})
HTML:
<div id="mylist">
<select id="myitems" size="5" onclick="GetSelectedText()">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
</select>
</div>