Skip to content

Instantly share code, notes, and snippets.

@bi0xid
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bi0xid/6e8b1ac0f086cd416303 to your computer and use it in GitHub Desktop.
Save bi0xid/6e8b1ac0f086cd416303 to your computer and use it in GitHub Desktop.
Send form using ctrl+enter / cmd+enter
window.onload = function () {
document.getElementById("commentform").onkeydown = function (e) {
if (e.keyCode == 13 && e.ctrlKey) { // keyCode 13 is Enter
document.getElementById("submit").click(); // submit the form by hitting ctrl + enter
// alert(e.keyCode); // to know other keyCodes of each keys
return false; // preventing default action
}
if (e.keyCode == 13 && e.metaKey) { // keyCode 13 is Enter
document.getElementById("submit").click(); // submit the form by hitting cmd + enter
// alert('test'); // to know other keyCodes of each keys
return false; // preventing default action
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment