Some times you want to disable the form submission when someone hits the enter key.
Here is how to do it.
[code language="javascript"]
// Ignores the enter key to prevent accidental form submission.
// Usage:
// src: http://jennifermadden.com/javascript/stringEnterKeyDetector.html
// src: http://www.w3schools.com/jsref/jsref_onkeypress.asp
function my_ignore_enter(e) {
var characterCode;
if (window.event) { // IE
characterCode = e.keyCode;
} else if(e.which) { // Netscape/Firefox/Opera
characterCode = e.which;
}
if (characterCode == 13) {
return false;
}
return true;
}
[/code]
Related
- http://jennifermadden.com/javascript/stringEnterKeyDetector.html
- http://www.w3schools.com/jsref/jsref_onkeypress.asp
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer