Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Prevent form submission with enter key #21

Closed
daviddarnes opened this issue Nov 11, 2014 · 1 comment
Closed

Prevent form submission with enter key #21

daviddarnes opened this issue Nov 11, 2014 · 1 comment

Comments

@daviddarnes
Copy link
Contributor

I've had to prevent my search form from submitting when people press enter, it was adding "?" to the url and therefore refreshing the page. I used the following to prevent it:

document.getElementById('search-field').addEventListener('keypress', function(event) {
    if (event.keyCode == 13) {
        event.preventDefault();
    }
});

I'm guessing this wouldn't be an issue if I didn't use a <form> element? Still might be good to prevent any submission?

@christian-fei
Copy link
Owner

Thanks for reporting.
I'll take a closer look at it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants