'Automatically click button when pressing either [Enter] key on keyboard

I'm sure this is really daft, but I can't wrap my head around it.

Basically, I have an input box on my site named 'search' where should a user press the [Enter] key, it will automatically select the button. I noticed however when the user presses the NUMLOCK [Enter] key, it doesn't submit.

What code needs to be added in to allow both [Enter] keys on the keyboard please? :)

            // Redirect when [Enter] key is pressed
            var search_keydown = document.getElementById("search"); 
            search_keydown.addEventListener("keydown", function (e) {
            if (e.code === "Enter") {
                redirect(); 
            }
            }); 

I thank you kindly. God, I love this site.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source