Javascript in HTML Prompt to detect keypress

I’d like to add some javascript to my HTML prompt to detect keypresses, I have seen examples of javascript for doing that, but none of them seem to work for a custom HTML prompt.

Following up on my own post, I was able to do it by adding this bit of javascript:

document.onkeydown = function(evt) {
    document.all.results.innerHTML = 'Got a keydown';
};

The problem now is that every time I type a key, I get a ‘BONK’ from the OS

Here is my complete ‘test’ HTML prompt

<html>
<body>
<div id="results">Results</div>
<script>
document.onkeydown = function(evt) {
    document.all.results.innerHTML = 'Got a keydown';
};
</script>
</body>
</html>