Skip to content

Instantly share code, notes, and snippets.

@KacperKozak
Last active May 4, 2024 12:24
Show Gist options
  • Save KacperKozak/9736160 to your computer and use it in GitHub Desktop.
Save KacperKozak/9736160 to your computer and use it in GitHub Desktop.
[Ctrl] + [Enter] to submit forms
document.body.addEventListener('keydown', (event) => {
if(event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
event.target.form?.submit();
}
});
@gareve
Copy link

gareve commented Apr 8, 2023

Most examples use JQuery, props for sharing a pure JS solution :)

@Fanoflix
Copy link

Since e.keyCode is deprecated, here is an updated Typescript snippet: ctrl-enter.ts

@KacperKozak
Copy link
Author

You're correct. This snippet is from 9 years ago, but it has been updated now :)

@berk-efe
Copy link

berk-efe commented Oct 7, 2023

beautiful thing i have ever seen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment