0

So, I want to be able to press enter while in a text field and be redirected to another page. Does anyone know how I can do this?

<input class="center" type="text"  style="font-size:20px; border:none; outline:none; " size="105" type="text" placeholder="Shrek" name="search" >
  • Does this answer your question? [Detect the Enter key in a text input field](https://stackoverflow.com/questions/7060750/detect-the-enter-key-in-a-text-input-field) – Elikill58 Nov 13 '21 at 09:47

1 Answers1

0

Edit: Replaced single and double quotes.

const search = document.querySelector('[name="search"]');

search.addEventListener('keyup', (e) => {
    if (e.code === 'Enter') {
        const url = 'https://example.com/';

        window.location.href = url;
    }
});
sitcomguy
  • 111
  • 1
  • 6